Possible Duplicate:
Create new class from a Variable in Java
I have a string
String className = "DummyClass"
Now I want to create a class object where the class name is className That is something like
Object className = new className() // I know it's not possible.
I want to know how to do this…
"Using
java.lang.reflect" will answer all your questions. First fetch theClassobject usingClass.forName(), and then:There is a
newInstance()method onClassthat might seem to do what you want. Do not use it. It silently converts checked exceptions to unchecked exceptions.