As I understand them, generics are a compile time feature of Java, and parametrized type information does not exist in the compiled byte code. I have now discovered the Field#getGenericType and Method#getGenericReturnType methods, thusly shattering my world view. Please help me to piece it together.
解决方案
The just runtime types of objects are erased. For instance:
Object obj = new ArrayList();
obj.getClass() will return ArrayList.class. You can even tell that ArrayList has a generic parameter. But there is no way to tell if obj was created as ArrayList, ArrayList, ArrayList, ArrayList (raw), or anything else.
Static type information is still there for class, methods, etc (although not for locals). This is just an extra bit of data appended as attributes in the class file, and available at runtime. Think of it much the same as annotations with runtime retention. Was there a question?