Community
Participate
Working Groups
jdt-core of 20050125 the following snippet compiles, javac gives: .../test1/DependentParameters.java:10: <Q,L>nextTry(Q,L) in test1.DependentParameters cannot be applied to (java.lang.Integer,java.lang.Number) new DependentParameters().nextTry(i, n); ^ 1 error -------- snip --------- package test1; public class DependentParameters { public static void main(String[] args) { Number n= null; Integer i= null; new DependentParameters().nextTry(i, n); } <Q,L extends Q> void nextTry(Q q, L l) { } }
Actually the solution eclipse finds seems correct as well - it resolves both Q and L to java.lang.Number. This fulfills both "L extends Q" as well as "Integer isa Number" and "Number isa Number" for the parameters. Not sure what the spec says.
During type inference, we indeed infer that Q is Number and not Integer.
Unfortunately, spec says we should not be that clever. We did check the variable bound (L extends Q) in first inference pass, to collect possible candidates; but we should only consider doing so in a later stage, when there was no match for Q.
Adjusted type argument inference support to defer bound check to later stage. So if candidate is found during method argument inference, it will prevail. Added GenericTypeTest#test494. Fixed
Verified in I20050214