public class Base {
public static void main(String[] args) {
Base b = new Derived();
b.printName();
}
public void printName() {
System.out.println(this.getClass());
}
}
class Derived extends Base {
}
the code above prints the derived class name. how can I make it print the base class name. Keep in mind that the code is used to classify the question. I don't actually need to print the class name. I need the this in printName be exactly the type of Base even in a Derived instance. It's has not be the name this, anything do the work would be OK. Is it possible?
To further specify the question. Some third party library I used in base class didn't get their job done in Derived class instance. And I figure it out that's because they called getClass() of the this I passed in but didn't get the Class<?> they expected. How can I workaround this?