This question already has an answer here:
- Get generic type of class at runtime 16 answers
I'm trying to use reflection to get a list of classes implementing an abstract class, Detector
. I would like to use the elements of this list (of type Class<T extends Detector>
) as a type parameter for another class, DetectorWrapper<T extends Detector>
, so that I can easily instantiate T
within that class (i.e., using new T(...)
). Is it possible to use reflection for this, or should I instead pass Class<T>
to DetectorWrapper
and use reflection to invoke the constructor whenever I need an instance of T
?
Aucun commentaire:
Enregistrer un commentaire