Not sure what you want to do, but if you want to create an object on the fly (ie at runtime), you would do :
Object o = Class.forName("com.acme.MyClass").newInstance();
This relys on the fact that your class has a default constructor.
If it does not have a default contstrucor, you need to use reflection to pass the desired parameters. Eg, to list all the Constructors :
Code:
Class c = Class.forName("com.acme.MyClass");
Constructor[] ctors = c.getConstructors();
for (int i = 0l i < ctors.length; i++) {
// look for you desired constuctor
// and then call the relevant newInstance() method on the
// ctor object
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.