这怎么可能是合法的? A不是由Intf实现的。因此,如何才能合法使用?Java - interface -instsnceof
interface Intf {
}
class A{
}
class B{}
class Test {
public static void main(String[] args) {
A obj = new A();
System.out.println(obj instanceof Intf); //Legal - no any errors, just output false
System.out.println(obj instanceof B); // Illegal - compile error
}
}
你的问题是什么?合法使用这个作为什么? –
你的印刷线声明的输出是什么?真正?假? “非法”? – deHaar
实际上做的是,它检查你的对象到特定的类或接口, 那么合法的含义是什么? –