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

Qualified static method reference reported as ambiguous by javac

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6
    • tools
    • x86
    • linux

      FULL PRODUCT VERSION :
      ava version "1.6.0_01"
      Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux nacar 2.6.18-suspend2-r1 #3 PREEMPT Tue Dec 26 21:51:39 COT 2006 i686 Intel(R) Pentium(R) M processor 2.00GHz GenuineIntel GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      A qualified reference to a static parametrized class method is reported as ambiguous by javac when the method hides one in its super class using different type parameters.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the following code:
      ---
      class A {
      public static Object create() {
      return null;
      }
      }

      class B extends A {
      public static<T> Object create() {
      return null;
      }
      public static void main(String... args) {
      Object b=B.create();
      }
      }
      ---

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      clean compilation
      :)
      ACTUAL -
      ... reference to create is ambiguous, both method create() in A and method <T>create() in B match
                      Object b=B.create();
                                ^
      1 error
      :(

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      ... reference to create is ambiguous, both method create() in A and method <T>create() in B match
                      Object b=B.create();
                                ^
      1 error

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class A {
      public static Object create() {
      return null;
      }
      }

      class B extends A {
      public static<T> Object create() {
      return null;
      }
      public static void main(String... args) {
      Object b=B.create();
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      - do not hide static methods with different type parameter specifications. (Use other method name)... But this makes my code more difficult to use because a more complex coding pattern must be followed. :(

            Unassigned Unassigned
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: