Is there any way to get this to work
String ClassName = "testing";
Classname.main();
testing.class is a class in the bin folder
if its important I'm using eclipse
Is there any way to get this to work
String ClassName = "testing";
Classname.main();
testing.class is a class in the bin folder
if its important I'm using eclipse
You can do something like this:
String aux = (String) (Class.forName("java.lang.String")).newInstance();
Then you can do what you want with aux
, for example calling a static method.
you can get the class like this:
public Object withName(String className) {
try{
Class<?> c = Class.forName(className);
Constructor<?> cons = c.getConstructor();
return cons.newInstance();
}catch (Exception e){
e.printStackTrace();
return null;
}
}
if you don't know which class it is,to find methods of desired class you can check this post: