In a method, I would like to get the classname for a class which is extended by another. But, if I call this method on the child, I have this child's name.
How can I refer to the class where the method is written? Not to the extended class.
In a method, I would like to get the classname for a class which is extended by another. But, if I call this method on the child, I have this child's name.
How can I refer to the class where the method is written? Not to the extended class.
When you have a class like
public class A {
}
You can reference the defining class by using A
(the class name). E.g.
public void do() {
System.out.println("Defined in " + A.class.getName());
}
If i understand correctly, you want to get the super-class's name.
using Reflection API:
Class subclass = o.getClass();
Class superclass = subclass.getSuperclass();
String className = superclass.getName();