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

RFE: Request for Clarification of JLS 15.12.2.2

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.0
    • specification
    • generic
    • generic

      Name: rmT116609 Date: 08/21/2001


      Request for clarification of JLS 15.12.2.2

      http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html


      15.12.2.2 of the JLS explains how methods are searched to find the most
      specific method and when the compiler warns of ambiguous methods. In
      the Java forum someone posted this query:

      http://forum.java.sun.com/thread.jsp?forum=31&thread=159240

      ----

      class Homer {
        float doh(float f) {
          System.out.println("doh(float)");
          return 1.0f;
        }

        char doh(char c) {
          System.out.println("doh(string)");
          return 'd';
        }
      }

      class Bart extends Homer {
        float doh(float f) {
          System.out.println("doh(float)");
          return 1.0f;
       }
      }

      class Hide {
        public static void main(String[] args) {
          Bart b = new Bart();
          b.doh('x');//compiler error in this line
          b.doh(1);
          b.doh(1.0f);
        }
      }

      An error was ocurred:reference to doh is ambigous

      ----
      Many people posted replies and it was clear that even after reading the JLS
      they were not clear if an error should be generated and why.

      After reading the specification a second time I believe I now understand it - though
      an example with ambiguity resulting from class inheritance would make it much
      easier to understand.

      PLEASE ADD AN APPROPRIATE EXAMPLE TO THE JLS.

      NOTE:
      It has been reported that Visual Age for Java does not produce an error with
      the above code (I have not been able to verify this). If this is the case it is
      clear that the specification is also unclear to JVM developers.

      ALSO DOES THE JAVA CERTIFICATION SUITE TEST THIS? IS IT POSSIBLE THAT A
      DIFFERENCE IN THE IBM PRODUCT HAS SLIPPED THROUGH THE NET?
      (Review ID: 129969)
      ======================================================================

            abuckley Alex Buckley
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: