JDK-4144488 : Allow covariant return types
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 1.1,1.2.0,5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_95,windows_xp
  • CPU: generic,x86
  • Submitted: 1998-06-01
  • Updated: 2004-08-30
  • Resolved: 2004-08-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 rcFixed
Related Reports
Duplicate :  
Duplicate :  
Description

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)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: tiger-rc INTEGRATED IN: tiger-rc
02-09-2004

WORK AROUND Name: rm29839 Date: 06/01/98 Lots of casting. Ewwww! ======================================================================
02-09-2004

PUBLIC COMMENTS Request to allow refining the return type of a method in a subtype. We may be able to accomodate this as a beneficial side effect of genericity See http://developer.java.sun.com/developer/jcp/jsr_014_gener.html Done in the upcoming release.
02-09-2004

EVALUATION Maybe as part of a generic types proposal we could deal with this. See comments. gilad.bracha@eng 1998-06-01 Done. ###@###.### 2004-08-30
01-06-1998