How do I instantiate Class Dynamically in Java?
Posted
by kunjaan
on Stack Overflow
See other posts from Stack Overflow
or by kunjaan
Published on 2010-05-31T22:53:11Z
Indexed on
2010/05/31
23:03 UTC
Read the original article
Hit count: 166
I have the class name stored in a property file. I know that the classes store will implement IDynamicLoad. How do I instantiate the class dynamically?
Right now I have
Properties foo = new Properties();
foo.load(new FileInputStream(new File("ClassName.properties")));
String class_name = foo.getProperty("class","DefaultClass");
//IDynamicLoad newClass = Class.forName(class_name).newInstance();
Does the newInstance only load compiled .class files? How do I load a Java Class that is not compiled?
© Stack Overflow or respective owner