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

I take issue with section 8.4.6.3 of the language spec

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • specification
    • generic
    • generic



      Name: gb36485 Date: 04/16/99


      This thows an error

      C:\WINDOWS\DESKTOP\Projects\b>type xx.java
      class A {A check() { return null; }}
      class B extends A { B check() { return null; }}
      C:\WINDOWS\DESKTOP\Projects\b>javac xx.java
      xx.java:6: The method B check() declared in class B
      cannot override the method of the same signature
      declared in class A. They must have the same
      return type.

        B check() { return null; }
          ^

      This is correct according to the jls 8.4.6.3. However,
      I think that when overriding a method, it ought to be
      permissable to narrow the type of the return value.
      In the fragment above, an object of class B is always
      going also to be of type A, as A is a subclass of A.
      This is in the same spirit as an overriding method
      being able to specify that it does not throw errors
      that a the superclass may. Restricting a subclass
      is always ok.
      (Review ID: 52365)
      ======================================================================

            Unassigned Unassigned
            gbrachasunw Gilad Bracha (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: