我正在读这个:
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.20.2
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.20.2
他们说:
Consider the example program:
class Point { int x,y; } class Element { int atomicNumber; } class Test { public static void main(String[] args) { Point p = new Point(); Element e = new Element(); if (e instanceof Point) { // compile-time error System.out.println("I get your point!"); p = (Point)e; // compile-time error } } }
The
instanceof
expression is incorrect because no instance ofElement
or any of its possible subclasses (none are shown here) could possibly be an instance of any subclass ofPoint
.
为什么这会导致错误,而不是简单地在返回false的情况下?
谢谢,
JDelage