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

Allow covariant return types

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.1, 1.2.0, 5.0
    • specification
    • rc
    • generic, x86
    • generic, windows_95, windows_xp



      Name: rm29839 Date: 06/01/98


      I suggest that the JLS be modified to allow a method to be overridden with a different return type, provided the return type of
      the overriding method is assignable to the return type of the method it is overriding. Specifically, section 8.4.6.3 would be
      changed from

      If a method declaration overrides or hides the declaration of another method, then a compile-time error occurs if they have
      different return types or if one has a return type and the other is void.


      to

      If a method declaration overrides or hides the declaration of another method, then a compile-time error occurs if the return
      type of the
      overriding method is not assignable to the return type of the overriden method, or if one has a return type and the other is void.

      That is, for instance, the method Object clone() from the class java.lang.Object could be overridden with, for instance

      public ThisClass clone(){
          return (ThisClass)super.clone();
      }

      because ThisClass is assignable to Object.
      (Review ID: 32255)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: