I need to store a reference to a class in a variable, such that I can call the static methods of that class on the variable.
Main.java
public class Main {
private static SomeClass cls;
private static void main(String[] args) {
**cls = SomeClass;**
cls.doSomething();
}
SomeClass.java
public class SomeClass() {
public static doSomething() {
}
}
cls = SomeClass is not working here, but I also don't want to instantiate SomeClass.
Can anyone help?
SomeClass.doSomething();cls = SomeClasswouldn't work with a non-static variable either. Did you meancls = new SomeClass();?private static Class<?> cls;and I would close this question as a duplicate of this one.