-
Enhancement
-
Resolution: Fixed
-
P4
-
1.1, 1.2.0, 5.0
-
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)
======================================================================
- duplicates
-
JDK-4106143 About polymorphism: changing the return type of an overloaded method to a subcla
- Closed
-
JDK-4191252 The Java language should allow covariant method return types
- Closed