Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6199075

Unambiguous varargs method calls flagged as ambiguous

XMLWordPrintable

    • 5.0
    • 5.0
    • b123
    • generic, x86
    • generic, linux_suse_sles_9
    • Verified

        $ cat -n Test.java
             1 class Test {
             2 public static void foo(int ...i) {}
             3 public static void foo(double...d) {}
             4
             5 public static void main(String[] args) {
             6 foo(1, 2, 3);
             7 }
             8 }
             9
        $ javac Test.java
        Test.java:6: reference to foo is ambiguous, both method foo(int...) in Test and method foo(double...) in Test match
                foo(1, 2, 3);
                ^
        1 error

        Javac is incorrect since int <: double which makes foo(int...) more specific than foo(double...).

              mcimadamore Maurizio Cimadamore
              ahe Peter Ahe
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: