-
Bug
-
Resolution: Not an Issue
-
P2
-
9
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."
SeeJDK-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.
"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
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.
- relates to
-
JDK-8009411 (reflect) Class.getMethods should not include static methods from interfaces
-
- Closed
-