Community
Participate
Working Groups
Using eclipse I20041201 on Mandrake linux. This first bit of code gives the message "Bounds mismatch: The generic method frenchify(Collection<? extends Phi<AA,BB>>, AA) of type Problem<A,B,P> is not applicable for the arguments (Collection<? extends Phi<A,BB>>, A) since the type A is not a valid substitute for the bounded parameter <AA extends Alpha<AA,BB>>." In fact, in that use of the static method, A and B are the substitutes for AA and BB. ==================================================================== import java.util.ArrayList; interface Alpha<A1 extends Alpha<A1,B1>, B1 extends Beta<A1,B1>> { } interface Beta<A2 extends Alpha<A2,B2>, B2 extends Beta<A2,B2>> { } interface Phi<A3 extends Alpha<A3,B3>, B3 extends Beta<A3,B3>> { public void latinize(A3 s); } public class Problem <A extends Alpha<A,B>, B extends Beta<A,B>, P extends Phi<A,B>> extends ArrayList<P> implements Phi<A,B> { public final void latinize(A a) { frenchify(this, a); } // ----------------------------------------------------------------- public static final <AA extends Alpha<AA,BB>, BB extends Beta<AA,BB>> void frenchify(Collection<? extends Phi<AA,BB>> phis, AA aa) { for(final Phi<AA,BB> phi : phis) phi.latinize(aa); } } ==================================================================== Note that this problem goes away when Alpha is not mutually recursive with other type bound: ==================================================================== import java.util.ArrayList; import java.util.Collection; interface Gamma<G1 extends Gamma<G1>> { } interface Psi<GP extends Gamma<GP>> { public void germanize(GP s); } public class Working<A extends Gamma<A>, P extends Psi<A>> extends ArrayList<P> implements Psi<A> { public final void germanize(A a) { anglicize(this, a); } // ----------------------------------------------------------------- public static final <AA extends Gamma<AA>> void anglicize(Collection<? extends Psi<AA>> psis, AA aa) { for(final Psi<AA> psi : psis) psi.germanize(aa); } } ==================================================================== All of these classes compile without error or warning on javac.
Reproduced in latest
Added regression test: GenericTypeTest#test433. Problem was in type inference algorithm which wasn't properly collecting substitutes for '? extends Phi<AA,BB>' using 'Problem<A,B,P>'. Allowed generic type to play correctly (as opposed to only parameterized types). Also tuned #findSuperTypeErasingTo for type variables, since they cannot use their erasure which is already a supertype. Fixed
Verified in 200412140800