【发布时间】:2017-08-10 09:24:26
【问题描述】:
任何人都可以使用 instanceof 运算符解释 Java 中的以下行为吗?
Runnable r = new Thread();
尽管变量 r 的类型是 Runnable 并且 instanceof 比较是在不在同一类层次结构中的类上完成的
System.out.println(r instanceof String); // This line does not compile
System.out.println(r instanceof Vector); // This line compiles
System.out.println(r instanceof FileNotFoundException); // This line compiles
【问题讨论】:
标签: java polymorphism instanceof