Add a warning when accessing a static method via an reference

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P5
    • 7
    • Affects Version/s: 1.4.1, 5.0
    • Component/s: tools
    • b86
    • generic, x86
    • generic, windows_xp
    • Not verified

      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)
      ======================================================================

            Assignee:
            Jonathan Gibbons
            Reporter:
            Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: