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

inconsistency in overload resolution at compile time

XMLWordPrintable

    • mantis
    • generic
    • generic, solaris_8
    • Verified



      Name: krT82822 Date: 10/07/99


      //Begin A1.java
      /*
       Why is in class A1 the invocation x.m(x) ambiguous and the two other
       invocations not? According to the JLS (15.11.2.2) all invocations are
       ambiguous. In all three cases both methods I/m(J) and J/m(I) are
       applicable.
       */

      interface I {
          void m(J x);
      }

      interface J extends I {
          void m(I x);
      }

      abstract class A1 implements J {
          void test(J x) {
              this.m(x); // invokevirtual m(J).
              ((A1) x).m(x); // invokevirtual m(J).
              x.m(x); // Reference to m is ambiguous.
          }
      }
      //End A1.java

      //Begin A2.java
      /*
       If we use abstract classes instead of interfaces, then all three
       invocations are ambiguous. Why are abstract classes treated
       differently?
       */

      abstract class I {
          abstract void m(J x);
      }

      abstract class J extends I {
          abstract void m(I x);
      }

      abstract class A2 extends J {
          void test(J x) {
              this.m(x); // Reference to m is ambiguous.
              ((A2) x).m(x); // Reference to m is ambiguous.
              x.m(x); // Reference to m is ambiguous.
          }
      }
      //End A2.java

      --------------

      10/7/99 eval1127@eng -- may be related to 4133897
      (Review ID: 93681)
      ======================================================================

            gafter Neal Gafter (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: