lundi 31 juillet 2017

Can guava be used for reflection on classes that are loaded by name?

In this question I was referred to guava as a solution for reflection on generics, and it looks awesome except that I get errors trying to use this on classes loaded by name:

Class clazz = Class.forName("net.redpoint.scratch.Derived");
TypeToken tt = new TypeToken(clazz) {};

This results in the error: java.lang.IllegalArgumentException: class com.google.common.reflect.TypeToken isn't parameterized

Is there some way to use TypeToken without having the class at compile-time? Note that I also do not have source to these classes.





Aucun commentaire:

Enregistrer un commentaire