Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6359949

@Override of static shouldn't be accepted (compiler shouldissue an error/warning)

XMLWordPrintable

    • b75
    • x86
    • windows_xp
    • Verified

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      I think that the @Override annotation should issue a compiler error/warning if it is applied to a static method.

      The following code compiles without any warnings:
      class Example {
          public static void example() {
              
          }
      }

      class Test extends Example {
          @Override
          public static void example() {

          }
      }

      Static methods can't be overridden, only hidden. I think that the code above might give a programmer a false indication that the method is indeed overridden and not just hidden.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Paste the code above in a source file, and compile with JDK 1.5.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect to get at least a warning from the compiler.
      ACTUAL -
      Nothing. I compiles fine without any warnings.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Example {
          public static void example() {
              
          }
      }

      class Test extends Example {
          @Override
          public static void example() {

          }
      }
      ---------- END SOURCE ----------

            ahe Peter Ahe
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: