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

Vararg method overloading fails

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux_suse_sles_9

      Description

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 10.0-b19, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      The following code is perfectly compilable by itself:

      public class OverloadTest {
          public static int min(int elt, int... elts) {
              int min = elt;
              for (int i : elts) {
                  if (i < min) {
                      min = i;
                  }
              }
              return min;
          }
       
          public static long min(long elt, long... elts) {
              long min = elt;
              for (long l: elts) {
                  if (l < min) {
                      min = l;
                  }
              }
              return min;
          }
       
      // public static void main(String[] args) {
      // int m = min(1, 2, 3);
      // }
      }

      Complier does distiguish the two signatures!
       
      However, an attempt to use any of those methods causes compile-time error:
                  Error: (27, 17) reference to min is ambiguous, both method min(int, int…) in OverloadTest and min(long, long …) in OverloadTest match

      The problem existed since Java 1.5



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      With main method commented out compile the OverloadTest class - it goes without any errors.
      Uncomment the main method and try to compile - compiler will error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Replacing vararg with primitive arrays works

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: