Community
Participate
Working Groups
Build Identifier: I20100129-1300 assume the example below: the compiler produces the following error: The method min(double, double, double[]) is ambiguous for the type Foo this happens as soon as I add the var arg. public class Foo { void foo() { int x1 = 1; int x2= 2; int y= min(x1, x2); } public static double min(double first, double second, double... others) { return first; } public static int min(int first, int second, int... others) { return first; } } Reproducible: Always
I think this is not an error. The error is legitimate. javac 1.5, 1.6 and 1.7 also reports the same error. Both min methods are valid matches for min(x1, x2).
lowering the severity then. Do you know the reasoning behind this error marker? still sounds like a bug to me, even if the javac compiler does the same :)
(In reply to comment #2) > lowering the severity then. Do you know the reasoning behind this error marker? > still sounds like a bug to me, even if the javac compiler does the same :) To cite (JLS 3.0) chapter and verse, - application of 15.12.2.1 tags both min methods as "potentially applicable". - 15.12.2.2 and 15.12.2.3 do not apply for the case at hand as these are concerned with matching (fixed) arity potentially applicable methods. - Application of 15.12.2.4 tags both the "potentially applicable" methods as "applicable variable arity methods" and since we now more than one choice, method overload resolution proceeds to 15.12.2.5, the selection of the "most specific method" - By the rules of 15.12.2.5, neither method is more specific than the other (since on the one hand, double is not a subtype of int and on the other hand int[] is not a subtype of double[]). So both methods are "maximally specific". Since these methods are not "override equivalent", the method call is ambiguous. While that is the lower level nitty gritty leading to the error, the seemingly counter-intuitive picture arises from the fact that there is a defined subtyping relationship among primitive types (4.10.1) by which int is a "subtype" of double, 4.10.3 does not define any subtyping relationship between arrays of primitive types so that int [] is not a subtype of double [].
verified for 3.6M6
Verified.
*** Bug 317586 has been marked as a duplicate of this bug. ***