Name: diC59631 Date: 11/11/98
// the class
public class MyClass {
// the constructor
public MyClass() {
// do something
}
// the method with the same name as constructor
public void MyClass() {
// do something
}
}
In other program, you can use the class like this:
// call the constructor
MyClass myclass = new MyClass();
// call the method public void MyClass()
myclass.MyClass();
The java complier allows this kind of usage, but it
looks confusing(It is not allowed in C++).
If you forgot to implement the constructor(with a
"void" before the method name), the code is also
allowed. But the default constructor does nothing,
so you maybe think it strange.
I think the java complier should check this situation,
and do not allow the method with the same name as
the constructor.
(Review ID: 42467)
======================================================================
- duplicates
-
JDK-4128179 # Add a lint-like facility to javac
-
- Closed
-