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

Class.getMethod[s] for static methods of interface

XMLWordPrintable

      In the JDK 8 the new assertion was added to the Class.getMethod[s] spec:
      "Static methods declared in superinterfaces of the class or interface represented by this Class object are not considered members of the class or interface."
      See JDK-8009411 for details.

      According to this assertion static methods declared in interface are not considered members of this interface. However, such methods are returned by the Class.getMethod[s] methods.

      Lets consider the following minimized test (failed JCK tests are under development):
      -----------------------------------------------------------------------------------------------------

      public class MinimizedTest {

          public static void main(String[] args) throws IOException {
              Method[] methods = I.class.getMethods();
              for (Method m : methods) {
                  System.out.println(m.getName());
              }
          }
      }

      interface I {
          static void m() {}
      }
      -----------------------------------------------------------------------------------------------------

      Expected that there will be no output, however the output will be:
      -----------------------------------------------------------------------------------------------------
      m

      -----------------------------------------------------------------------------------------------------

      Probably, the problem is only in the spec, it is vague and need to be clarified.

            dlsmith Dan Smith
            evotchen Elena Votchennikova (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: