Community
Participate
Working Groups
Our systems: - Eclipse 3.1M2 - both Mandrake 10.0 and Windows 2000 In the code below, there are two incorrectly reported errors in method goK about classes K1/K2. (1) Bound mismatch: The generic method kk(K1<B>) of type K1<A> is not applicable for the arguments (K1<YY>) since the type YY is not a valid substitute for the bounded parameter <B extends A> (2) Bound mismatch: The generic method kk(K1<B>) of type K1<A> is not applicable for the arguments (K1<ZZ>) since the type ZZ is not a valid substitute for the bounded parameter <B extends A> K1/K2/goK compile and run correctly under Sun JDK 1.5.0. Note that M1/M2 work correctly under this Eclipse. but fail under that Sun JDK (although L1/L2 work on both, implying M1/M2 should work). Reported this as their bug #6176664 http://bugs.sun.com:80/bugdatabase/view_bug.do?bug_id=6176664 in which they suggest reporting M1/M2 as a bug to Eclipse although we're of the opinion that Eclipse is right about M1/M2. (So to compile K1/K2 under Sun JDK, remove M1/M2 and their uses.) // // // Code begins here interface K1<A> { public <B extends A> void kk(K1<B> x); } class K2<C> implements K1<C> { public <D extends C> void kk(K1<D> y) { System.out.println("K2::kk(" + y.toString() + ")"); } } // --------------------------------------------------- interface L1<E> { public void ll(L1<? extends E> a); } class L2<KK> implements L1<KK> { public void ll(L1<? extends KK> b) { ll2(b); } private <LL extends KK> void ll2(L1<LL> c) { System.out.println("L2::ll2(" + c.toString() + ")"); } } // --------------------------------------------------- interface M1<H> { public void mm(M1<? extends H> p); } class M2<I> implements M1<I> { public <J extends I> void mm(M1<J> q) { System.out.println("M2::mm(" + q.toString() + ")"); } } // =================================================== class XX { public String toString() { return "XX"; } } class YY extends XX { public String toString() { return "YY"; } } class ZZ extends YY { public String toString() { return "ZZ"; } } // --------------------------------------------------- class Exec { public static void main(String arg[]) { goK(new K2<YY>()); goL(new L2<YY>()); goM(new M2<YY>()); } public static void goK(K1<YY> k) { // k.kk(new K2<XX>()); // Would fail k.kk(new K2<YY>()); k.kk(new K2<ZZ>()); } public static void goL(L1<YY> l) { // l.ll(new L2<XX>()); // Would fail l.ll(new L2<YY>()); l.ll(new L2<ZZ>()); } public static void goM(M1<YY> m) { // m.mm(new M2<XX>()); // Would fail m.mm(new M2<YY>()); m.mm(new M2<ZZ>()); } }
JDT compiler still complains with last build I200410260800.
We get now one additional compiler problem: "Name clash : The method mm(M1<J>) of type M2<I> has the same erasure as mm(M1<? extends H>) of type M1<I> but does not override it"
Adjusted code for better substituting through generic method declaring class. Added regression test: GenericTypeTest#test397. Fixed
Note that we still issue the nameclash issue: "Name clash : The method mm(M1<J>) of type M2<I> has the same erasure as mm(M1<? extends H>) of type M1<I> but does not override it"
Verified in 200412140800