Considering following code
public class A {
public static void main(String[] args) {
new A().main();
}
void main() {
B b = new B();
Object x = getClass().cast(b);
test(x);
}
void test(Object x) {
System.err.println(x.getClass());
}
class B extends A {
}
}
I expected as output "class A" but i get "class A$B".
Is there a way to cast down the object x to A.class so when using in a method call the runtime will think x is of A.class ?