I take issue with section 8.4.6.3 of the language spec

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 1.2.0
    • Component/s: 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)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: