-
Bug
-
Resolution: Unresolved
-
P4
-
21
-
None
Consider this example:
package p1; public class A { void m() { System.out.println("A.m"); } }
package p2; public class B extends p1.A { } // different package
package p1; public class C extends p2.B {
@Override public void m() { System.out.println("C.m"); }
public static void main(String[] args) { ( (A) new C() ).m(); }
}
Compile and run it:
% javac -sourcepath . p1/*.java p2/*.java
% java -classpath . p1.C
C.m
Printout "C.m" is expected and correct because C.m overrides A.m from C. This case is covered by JLS 8.4.8.1. Overriding (by Instance Methods):
> * mA is declared with package access in the same package as C, and either C declares mC or mA is a member of the direct superclass type of C.
Indeed, while C declares mC (here m), mA (here m) is not a member of the direct superclass type of C (here B) because A.m has package access in p1, which is different from p2, where B is declared.
However, when examined programmatically, using javax.lang.model, the call below incorrectly returns false; pseudocode:
Elements.overrides(C.m, A.m, C) == false
package p1; public class A { void m() { System.out.println("A.m"); } }
package p2; public class B extends p1.A { } // different package
package p1; public class C extends p2.B {
@Override public void m() { System.out.println("C.m"); }
public static void main(String[] args) { ( (A) new C() ).m(); }
}
Compile and run it:
% javac -sourcepath . p1/*.java p2/*.java
% java -classpath . p1.C
C.m
Printout "C.m" is expected and correct because C.m overrides A.m from C. This case is covered by JLS 8.4.8.1. Overriding (by Instance Methods):
> * mA is declared with package access in the same package as C, and either C declares mC or mA is a member of the direct superclass type of C.
Indeed, while C declares mC (here m), mA (here m) is not a member of the direct superclass type of C (here B) because A.m has package access in p1, which is different from p2, where B is declared.
However, when examined programmatically, using javax.lang.model, the call below incorrectly returns false; pseudocode:
Elements.overrides(C.m, A.m, C) == false