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

method that is not ambiguous

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      openjdk version "1.8.0_111"
      OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14)
      OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The java file attached does not compile. Instead javac fails with

      Test.java:9: error: reference to method is ambiguous
      method(MyClass::new);
      ^
        both method <T>method(Supplier<T>) in Test and method <E>method(E) in Test match
        where T,E are type-variables:
          T extends Object declared in method <T>method(Supplier<T>)
          E extends Enum<E> declared in method <E>method(E)
      1 error

      It should compile and run, as it does within eclipse Version: Mars.2 Release (4.5.2) Build id: 20160218-0600


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile and run the java file attached

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      output:

      Enum one
      Supplier class Test$MyClass
      Supplier class Test$MyClass

      ACTUAL -
      compiler failure

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.function.Supplier;

      public class Test
      {
      public static void main(final String[] args)
      {
      method(MyEnum.one);
      method((Supplier<MyClass>)MyClass::new);
      method(MyClass::new);
      }


      static <T> void method(final Supplier<T> v)
      {
      System.out.println("Supplier " + v.get().getClass());
      }

      static <E extends Enum<E>> void method(final E v)
      {
      System.out.println("Enum " + v);
      }


      enum MyEnum { one, two }

      static class MyClass
      {
      MyClass() {}
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The cast in line 8 of the java file attached

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: