Community
Participate
Working Groups
Using latest, these two interfaces are incompatible. interface I { Number foo(); } interface J { Integer foo(); } This means that it is not possible to compare them using instanceof. Even if the result of the instanceof call is false, at least it compiles. interface I { Number foo(); } interface J { Integer foo(); } public class X implements I, J { public Integer foo() {return 1;} public static void main(String argv[]) { I c1 = null; System.out.print(c1 instanceof J); } } ---------- 1. ERROR in C:\tests_sources\X.java (at line 13) System.out.print(c1 instanceof J); ^^^^^^^^^^^^^^^ Incompatible conditional operand types I and J ---------- 1 problem (1 error)
Expression#checkCastTypeCompatibility need to be tuned to support covariance/substitution. Need some entry point in method verifier.
Philippe: So what question do you need to ask?
In this block of code near the bottom of the cast compatibility rules, we are checking whether the 2 interfaces are cast compatible: ... for (int j = 0; j < exprMethodsLength; j++) { if ((castTypeMethods[i].returnType != expressionTypeMethods[j].returnType) && (CharOperation.equals(castTypeMethods[i].selector, expressionTypeMethods[j].selector)) && castTypeMethods[i].areParametersEqual(expressionTypeMethods[j])) { return false; ... these rules obviously do not play the 1.5 semantics. Please check how JLS3 have evolved on this very topic. I suspect you need to compare methods in a similar way to what method verifier does when determining if one overrides another one.
Added MethodVerify test033
Actually, rules are even simpler. We always allow cast to interface from 1.5 on (a subtype may implement it).
also see bug 84743
Verified in I20050215-2300