How can I get a reference to a Subclass’s Class from a Superclass method?
E.g.,
public class MySuper {
public void myMethod(){
// here i need a reference to MySub1.class or MySub2.class
// depending on the class of the instance that invoked this method
}
}
public class MySub1 extends MySuper {
public String myString;
}
public class MySub2 extends MySuper {
public int myInt;
}
Sounds like you just want:
Or more explicitly:
Note that it won’t be the class containing the code that invoked the method – it’ll be the class of the object that the method was invoked on. If you want the class of the caller, that’s a whole different matter.