C
chauvin.mathieu
Hi.
I would like to find, at run-time, the actual return type of a generic
method.
For a parameterized return type, that's OK, but what about a
TypeVariable return type ??
Suppose we have the following:
abstract class Generic<T> {
private T genericInstance;
public T getGeneric() {
return genericInstance;
}
public void setGeneric(T instance) {
genericInstance = instance;
}
}
// Recursive structure
class Concrete extends Generic<Concrete> {
}
The class Concrete actually defines a method which looks like:
public Concrete getGeneric();
But I just can't figure out, and I don't even know if it's possible,
how to find that this method returns an instance of Concrete.
Concrete.class.getMethod("getGeneric", null).getGenericReturnType()
returns a TypeVariable, and I just can't see how to do from it !
Thanks !
Mathieu
I would like to find, at run-time, the actual return type of a generic
method.
For a parameterized return type, that's OK, but what about a
TypeVariable return type ??
Suppose we have the following:
abstract class Generic<T> {
private T genericInstance;
public T getGeneric() {
return genericInstance;
}
public void setGeneric(T instance) {
genericInstance = instance;
}
}
// Recursive structure
class Concrete extends Generic<Concrete> {
}
The class Concrete actually defines a method which looks like:
public Concrete getGeneric();
But I just can't figure out, and I don't even know if it's possible,
how to find that this method returns an instance of Concrete.
Concrete.class.getMethod("getGeneric", null).getGenericReturnType()
returns a TypeVariable, and I just can't see how to do from it !
Thanks !
Mathieu