Say I have these classes:
class Container<T> {
private List<T> list;
}
And I have an instance of Container
, say
Container<?> instance = new Container<String>();
Is there a way to find out list
's actual type parameter at run-time? I.e., that it's a List
of String
, rather than a List
of java.lang.reflect.TypeVariable
.
I've been looking at Java's reflection (field.getGenericType()
), various libraries (Guava Reflect, Typetools, ClassMate, even ASM, etc.) but I can't figure it out.
I have no control over the Container
type, so I can't add any fields to it.
I realize it may not be possible at all due to erasure, although I don't mind messing with bytecode if that makes it possible.
Aucun commentaire:
Enregistrer un commentaire