Well, after digging around I found out I was supposed to do something like:
Code:
Class<?> c = Class.forName("MySingleton");
Method m = c.getDeclaredMethod("getInstance", new Class[0]);
Object obj = m.invoke(null, new Object[0]);
But I'm getting the following exception:
Code:
java.lang.NoSuchMethodException: MySingleton.getInstance()
at java.lang.Class.getDeclaredMethod(Class.java:1954)
at myProg.main(myProg.java:21)
Really strange because that class does in fact have a getInstance() method... as such:
Code:
/**
* Gets single instance of the site
* @return the site
*/
public static MySingleton getInstance() {
if(instance == null) {
instance = new MySingleton();
}
return instance;
}
Note: I replaced the real singleton class name with "MySingleton".
Edit: Woops my bad, it seems that I was editing the wrong "MySingleton" file. It works. Thanks.