vendredi 1 mai 2015

Is it possible to reconstruct generic return type with help of reflection - Java?

I have the following code snippet (it is just example):

public class Class123 extends Thread implements Serializable, Runnable {
    public <T extends String> T callFriend(String name, Class<T> type) {
        return "";
    }
}

Is it possible to get <T extends String> T?

method.getGenericReturnType() == "T"
method.getReturnType().getName() == "java.lang.String"

My second example is:

public abstract class Function<T, R> {

    public <V> Function<T, V> then(Function<? super R, ? extends V> after) {
        return new Function<T, V>() {
            @Override
            public V apply(T t) {
                return after.apply(Function.this.apply(t));
            }
        };
    }

    public abstract R apply(T t);
}

And I want to get: <V> Function<T, V>.





Aucun commentaire:

Enregistrer un commentaire