Blocks :
|
|
CSR :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
The following program: import java.util.stream.Collectors; import java.util.stream.Stream; public class GetMethodTest { static void test(Class<?> clazz) throws Exception { System.out.println(clazz.getName() + ".class.getMethods(): " + Stream .of(clazz.getMethods()) .filter(m -> m.getDeclaringClass() != Object.class) .collect(Collectors.toList())); System.out.println(clazz.getName() + ".class.getMethod(\"m\"): " + clazz.getMethod("m")); } public static void main(String[] args) throws Exception { test(B.class); } } interface I { void m(); } interface J extends I { default void m() {} } abstract class A implements I {} abstract class B extends A implements J {} Prints: B.class.getMethods(): [public default void J.m()] B.class.getMethod("m"): public abstract void I.m() I think that getMethods() gets it right. getMethod() stops searching (super)interfaces as soon as a method is found on superclass (here the superclass is A, which inherits I.m abstract method). It should consolidate this abstract method with possible default methods comming from (super)interfaces that might override this method.
|