|
Duplicate :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
Name: rl43681 Date: 06/17/2003
A DESCRIPTION OF THE REQUEST :
The compiler allows static methods to be accessed as if they are instance methods. This can be a source of confusion when reading code.
It would be clearer if all calls to static methods had to be prefixed with the class name - but forcing this would break a lot of existing code.
It would be nice if the compiler had an option to warn when a static method is called without the class name being prefixed.
JUSTIFICATION :
To enhance the readabiloty of code (feel free to argue that it'll make the code harder to read - but hey that is why it is an option).
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compiler emit a warning (if the user specifies the flag) when a static method is called without being prefixed by the class name.
---------- BEGIN SOURCE ----------
public class X {
public static void main(final String[] argv) {
X x = new X();
x.foo(); // warning - reference not a class
X.foo(); // OK
}
public static void foo() {}
void bar() {
foo(); // warning - no class prefix
X.foo(); // OK
}
}
---------- END SOURCE ----------
(Review ID: 185711)
======================================================================
|