我有这段代码(Child 只是 Object 的一个空子),但我不明白为什么最后一次调用与第二次调用的结果不同
感谢帮助
public class App {
void process(Object o) {
System.out.println("I have processed an object");
}
void process(Child c) {
System.out.println("I have processed a child");
}
public static void main (String[] args) {
Object o = new Child();
Class<?> cl = Child.class;
App app = new App();
app.process(o);
app.process(Child.class.cast(o));
app.process(cl.cast(o));
}
}
输出是
I have processed an object
I have processed a child
I have processed an object