Name: rmT116609 Date: 02/12/2002
FULL PRODUCT VERSION :
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
The compiler should give an error when you attempt to define a constructor but you mistakenly include a return type. To put it another way, it should not assume its a legitimate method name if the method name matches the class
name.
Is there any reason for allowing non-constructor methods to have the same name as the class, other than obfuscation?
This is in the Sun Java bug database as Bug Id 1238736 from way back in 1996. At that time they decided it was not a bug, which is probably true, so I have entered it as a request for enhancement.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the code below in source code section
EXPECTED VERSUS ACTUAL BEHAVIOR :
Give a compiler error: "Return type not allowed with a constructor."
ERROR MESSAGES/STACK TRACES THAT OCCUR :
The problem is that no compiler message is given.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class MyClass {
void MyClass() {
}
int MyClass(int foo) {
return(3);
}
}
---------- END SOURCE ----------
(Review ID: 139597)
======================================================================
- duplicates
-
JDK-4593045 warnings desired for almost certain errors
-
- Open
-