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

new varargs ambiguity error

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      The fix to 7042566(?) results in two methods such as
        void foo(int... ia) {}
        void foo(Object... oa {}
      as now seen as both matching when foo is given two ints.
      Test code:

      public class test4 {
          public int foo(int ... vai) { return 1; }
          public int foo(Object ... vaO) { return 2; }

          //TEST: choose best of overloaded methods
          public int test() {
              int i1 = 1;
              int i2 = 2;
              int ret = foo(i1,i2); //should choose method 1
              return ret;
          }

          public static void main(String[] args) {
            test4 tv = new test4();
            System.out.println( tv.test()==1?"PASS":"FAIL" );
          }
      }

      Error message:
      h:\ws\7_int\tools\src\javac\varargs\test4]javac test4.java
      test4.java:18: error: reference to foo is ambiguous, both method foo(int...) in test4 and method foo(Object...) in test4 match
              int ret = foo(i1,i2); //should choose method 1
                        ^
      1 error

      Attachments

        Issue Links

          Activity

            People

              mcimadamore Maurizio Cimadamore
              ssides Steve Sides
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: