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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -