Community
Participate
Working Groups
The following sample code does not compile. The error message reported in the main method is: "the method doSomething(Collection<?>) is ambiguous" package com.neppert; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.RandomAccess; public class TestOverloads { public static void doSomething(Collection<?> collection) { } public static <C extends List<?>> void doSomething(C list) { } public static void main(String[] args) { doSomething(new ArrayList<String>(Arrays.asList("hallo"))); } }
I verified that using JDK 1.5.0_08, javac does not complain on this code...
Reproduced with HEAD. According to JLS 15.12.2, the second method is strictly more specific than the first one, hence maximally specific, and being the sole method to be maximally specific, it is the most specific method, and the call is not ambiguous. Added (inactive) test cases #23 and 24 to AmbiguousMethodTest.
We rawify a bit too aggressively the parameters in ParametrizedGenericMethodBinding#tiebreakMethod in the case of a static method. A first attempt to fix that failed in the cases where the caller was already rawified. Currently testing less an agressive approach (using the upper bounds to build a parametrized generic method to use as the tiebreak).
Created attachment 52197 [details] Fix + test case In case the considered method is static, we build a tiebreak method that does not rawify its arguments types.
Released for 3.3 M3.
Verified for 3.3 M3 using warm-up build I20061030-0800