私はこれを読んでいます:
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.20.2
彼らが言うには:
サンプルプログラムを考えてみましょう:
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
}
}
}
のインスタンスも、その可能なサブクラス (ここには表示されていません) も、 のサブクラスのインスタンスになる可能性が
instanceof
ないため、式は正しくありません。Element
Point
instanceof
単純にfalse を返すのではなく、なぜこれがエラーになるのでしょうか?
ありがとう、
JDelage