Say, I have a reference to a Class object with SomeType having a static method. Is there a way to call that method w/o instantiating SomeType first? Preferably not escaping strong typing.
EDIT: OK, I’ve screwed up.
interface Int{
void someMethod();
}
class ImplOne implements Int{
public void someMethod() {
// do something
}
}
Class<? extends Int> getInt(){
return ImplOne.class;
}
In this case someMethod() can’t be static anyways.
A static method, by definition, is called on a class and not on an instance of that class.
So if you use:
you are instantiating nothing (leave aside the class loading and instantiation of the
SomeClassclass itself, which the JVM handles and is way out of your scope).This is opposed to a regular method called on an object, which has already been instantiated: