-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.0.2, 1.2.0
-
x86, sparc
-
solaris_2.5, windows_95
The compiler (1.0.2) rejects code in which a subclass overrides a method with a different return type that is assignable to the overridden method's return type.
The following code:
public class test1
{
test1 fredfunc() {return null;}
}
class test2 extends test1
{
test2 fredfunc() {return null;}
}
produces the following error from the compiler:
test1.java:8: Method redefined with different return type: test2 fredfunc() was
test1 fredfunc()
test2 fredfunc() {return null;}
^
1 error
According to the 1.0 Beta version of the language specification, page 48:
"The return type of an overriding method must be assignable to the return type of the overridden method."
Perhaps this has changed in the 1.0.2 version of the language specification, but since the relevant chapter of the newer language specification isn't available, I couldn't check it.
The following code:
public class test1
{
test1 fredfunc() {return null;}
}
class test2 extends test1
{
test2 fredfunc() {return null;}
}
produces the following error from the compiler:
test1.java:8: Method redefined with different return type: test2 fredfunc() was
test1 fredfunc()
test2 fredfunc() {return null;}
^
1 error
According to the 1.0 Beta version of the language specification, page 48:
"The return type of an overriding method must be assignable to the return type of the overridden method."
Perhaps this has changed in the 1.0.2 version of the language specification, but since the relevant chapter of the newer language specification isn't available, I couldn't check it.