Community
Participate
Working Groups
Build ID: M20080221-1800 Steps To Reproduce: Test case below: package test; public class TestGeneric< T extends Comparable<T> > { T[] array; public boolean equals(Object o) { if (array.length == ( (TestGeneric<Comparable<T>>) o).array.length) { return true; } return false; } } Error for eclipse 3.3.2 : Bound mismatch: The type Comparable<T> is not a valid substitute for the bounded parameter <T extends Comparable<T>> of the type TestGeneric<T> No error for Eclipse 3.3.1.1 M20071023-1652. No error for javac 1.6.0_03. More information:
Was mis-categorized as APT - changed subcomponent to Core.
javac doesn't perform bound checks on cast type !? public class X<T extends Comparable<T>> { T[] array; public boolean equals(Object o) { X<Comparable<T>> x; if (array.length == ((X<Comparable<T>>) o).array.length) { return true; } return false; } } It only notices the first type inconsistency ("X<Comparable<T>> x;"), not the second one. >javac X.java -d ..\bin -Xlint X.java:5: type parameter java.lang.Comparable<T> is not within its bound X<Comparable<T>> x; ^ X.java:6: warning: [unchecked] unchecked cast found : java.lang.Object required: X<java.lang.Comparable<T>> if (array.length == ((X<Comparable<T>>) o).array.length) { ^ 1 error 1 warning
Javac now reports 2 errors on scenario from comment 2 as expected in Java(TM) SE Runtime Environment (build 1.7.0-ea-b42).
Added GenericTypeTest#test1442. Closing as worksforme since our behavior is the expected one (since 3.3.2)
Verified for 3.5M5 using build I20090127-0100 and JRE 7.0 build 1.7.0-ea-b43