JDK-4880220 : Add a warning when accessing a static method via an reference
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.1,5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2003-06-18
  • Updated: 2013-09-13
  • Resolved: 2011-10-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b86Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
17-07-2004

PUBLIC COMMENTS ...
17-07-2004

EVALUATION Good idea. ###@###.### 2003-06-18
18-06-2003