Here is my code.
First, I have two classes:
public abstract class AbstractTypeReference<T> {
public Type type();
public AbstractTypeReference() {
Type superClass = getClass().getGenericSuperclass();
type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
}
}
public class MyTypeReference<T> extends AbstractTypeReference<T> {
public MyTypeReference() {
super();
}
}
Then, I run following code:
MyTypeReference<String> ref = new MyTypeReference<String>();
System.out.println(ref.type.toString());
I expect to get java.lang.String
as output, but get T
instead. The code was copied from com.fasterxml.jackson.core.type
. But it works well. Could anyone tell me what is wrong? And why?
Aucun commentaire:
Enregistrer un commentaire