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

8.4.8.2 Static methods of classes shouldn't hide interface statics

    Details

    • Type: Bug
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 12
    • Fix Version/s: None
    • Component/s: specification
    • Labels:
      None

      Description

      "If a class C declares or inherits a static method m, then m is said to hide any method m', where the signature of m is a subsignature (§8.4.2) of the signature of m', in the superclasses and superinterfaces of C that would otherwise be accessible (§6.6) to code in C."

      In fact, javac does not produce an error if a static method in a class would illegally hide a static method in a superinterface.

      public class Hiding {

          static class A {
              static int m() { return 3; }
          }

          interface B {
              static int n() { return 3; }
          }

          static class C extends A implements B {
              static String m() { return "3"; } // error
              static String n() { return "3"; } // no error
          }
      }

      This behavior is consistent with the treatment for interfaces, where an interface method cannot override/hide a superinterface's static method (see 9.4.1).

      Because static interface methods are not inherited, there is no reason to place any restrictions on the return type, etc., of a method that shares a name with a static superinterface method.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dlsmith Dan Smith
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: