dimanche 16 août 2015

Java reflection get runtime type when using generics

I am wondering how can I get the runtime type which is written by the programmer when using generics. For example if I have class Main<T extends List<String>> and the programmer write something like

Main<ArrayList<String>> main = new Main<>();

how can I understand using reflection which class extending List<String> is used?

I'm just curious how can I achieve that. With

main.getClass().getTypeParameters()[0].getBounds[] 

I only can understand the bounding class (not the runtime class).





Aucun commentaire:

Enregistrer un commentaire