java - Convert String into Class reference -
i want know if know how convert string class reference.
i think example enough understand why im asking
string classname = "mainclass"; if(annotation instanceof classname) the idea use string reference of class, if name of class "mainclass.java" can create comparation of "instanceof" string contain name of class mistake in code, because instanceof comparation of object specific class
some help? thanks!
you want class.forname(string) method:
http://docs.oracle.com/javase/7/docs/api/java/lang/class.html#forname(java.lang.string)
that return class<?> instance, can use check if object instance of, so:
final class<?> myclass = class.forname(classnamestring); return myclass.isinstance(myobject);
Comments
Post a Comment