Community
Participate
Eclipse IDE
3.1 - have the code below - javac complains, ecj does not - running the code produces a CCE in Integer.compareTo(Integer) ----- snip ----- class Hover { <T extends Comparable<T>> boolean isGreater(T t1, T t2) { return t1.compareTo(t2) > 0 ? true : false; } void method(Integer i, Double d) { isGreater(i, d); } } ---------------- ----- javac output ----- javac 1.5.0_03 /opt/eclipse/workspaces/runtime/workbench/Article/src/com/example/Hover.java:14: <T>isGreater(T,T) in com.example.Hover cannot be applied to (java.lang.Integer,java.lang.Double) isGreater(i, d); ^ 1 error
------- this fails correctly ---- void method(Integer i, Double d) { Comparable<? extends Number> c1= i; Comparable<? extends Number> c2= d; isGreater(c1, c2); } ---------- and this warns correctly ---- void method(Integer i, Double d) { Comparable c1= i; Comparable c2= d; isGreater(c1, c2); }
Problem comes from the fact an intersection type is handled as a wildcard when performing bound check. Fixed. Added GenericTypeTest#test790
*** Bug 106284 has been marked as a duplicate of this bug. ***
Opened bug 106514 to suggest an improvement of the error message. But since we now have an error, this bug is Verified in 3.2 M1 with build I20050808-2000.
Verified using M20050923-1430 for 3.1.1