United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4144488 Allow covariant return types
JDK-4144488 : Allow covariant return types

Details
Type:
Enhancement
Submit Date:
1998-06-01
Status:
Resolved
Updated Date:
2004-08-30
Project Name:
JDK
Resolved Date:
2004-08-30
Component:
specification
OS:
generic,windows_xp,windows_95
Sub-Component:
language
CPU:
x86,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.1,1.2.0,5.0
Fixed Versions:
5.0 (rc)

Related Reports
Duplicate:
Duplicate:

Sub Tasks

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
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
                                     
1998-06-01
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.
                                     
2004-09-02
WORK AROUND



Name: rm29839			Date: 06/01/98


Lots of casting.  Ewwww!
======================================================================
                                     
2004-09-02
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
generic

FIXED IN:
tiger-rc

INTEGRATED IN:
tiger-rc


                                     
2004-09-02



Hardware and Software, Engineered to Work Together