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

Static methods are implicitly final, but they can't be explicitly final

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0fcs
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Not verified

      Description

          The language document (I'm looking at the beta draft of July 29, 1995
      9:42 am, Section 5.6.2 Method Modifiers on page 32) says:

      A static method is implicitly final, so no overriding occurs on static
      methods

      which does seem to be true, but if I try to make a static method explicitly
      final, I find I can't declare another static method with the same name in a
      subclass. For example:

          % cat java/Base.java
          public class Base {
      public static final String method() {
      return "Base.method()";
      }
          }
          % cat java/Derived.java
          public class Derived extends Base {
      public static String method() {
      return "Derived.method";
      }
          }
          % ..../jdk.prebeta.1/bin/javac .... ./java/Derived.java
          ./java/Derived.java:2: Final methods can't be overriden. Method java.lang.String method() is final in class Base.
      public static String method() {
      ^
          1 error

      I guess you could say this is a bug in the documentation, but I think the
      documentation is correct, in terms of the effect of declaring a method
      static keeping it from being overridden by subclasses. I think the bug is
      in the compiler, which should allow static methods to be explicitly
      declared final.

      ... peter 10/16/95

        Attachments

          Activity

            People

            • Assignee:
              fyellinsunw Frank Yellin (Inactive)
              Reporter:
              pbk Peter Kessler
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: