开发者

Android Class.getGenericSuperclass returns java.lang.Object

I am trying to read generic info from a class. Here is what I am doing: first of all I have a class EntityHelper. Somewhere inside it I want to see what is actually that T. I know this can be done with:

(Class<T>) ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];

b开发者_如何学Pythonut what method getGenericSuperClass returns is java.lang.Object - which is not correct since I know T is something else, for example DummyEntity.

Android platform I use is 7. Is this some kind of a bug or I am missing something important?


You can not get the generic type of the argument. Generics are implemented using a technique called type erasure. Only way to achieve this effect is to save the Class<T> type( i.e. Use Class Literals as Runtime-Type Tokens ).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜