📄 reflectinterfaces.java
字号:
/* * The Art of Reflecting Interfaces. */import java.lang.reflect.Method;public class ReflectInterfaces{ interface If1 { public void if1Method(); void if1MethodNP(); public void if1MethodTH() throws Throwable; } interface If2 extends If1 { public void if2Method(); void if2MethodNP(); public void if2MethodTH() throws Throwable; } abstract class C1 implements If2 { } public static void main(String av[]) { Class c = If2.class; Class sc = c.getSuperclass(); System.out.println((sc == null?"null":sc.getName())); System.out.println("all methods"); Method [] m = c.getMethods(); for (int i = 0; i < m.length; i++) System.out.println(m[i].toString()); System.out.println("declared methods"); m = c.getDeclaredMethods(); for (int i = 0; i < m.length; i++) System.out.println(m[i].toString()); c = C1.class; m = c.getDeclaredMethods(); for (int i = 0; i < m.length; i++) System.out.println(m[i].toString()); }}// Sort Output/* Expected Output:all methodsdeclared methodsnullpublic abstract void ReflectInterfaces$C1.if1Method()public abstract void ReflectInterfaces$C1.if1MethodNP()public abstract void ReflectInterfaces$C1.if1MethodTH() throws java.lang.Throwablepublic abstract void ReflectInterfaces$C1.if2Method()public abstract void ReflectInterfaces$C1.if2MethodNP()public abstract void ReflectInterfaces$C1.if2MethodTH() throws java.lang.Throwablepublic abstract void ReflectInterfaces$If1.if1Method()public abstract void ReflectInterfaces$If1.if1MethodNP()public abstract void ReflectInterfaces$If1.if1MethodTH() throws java.lang.Throwablepublic abstract void ReflectInterfaces$If2.if2Method()public abstract void ReflectInterfaces$If2.if2Method()public abstract void ReflectInterfaces$If2.if2MethodNP()public abstract void ReflectInterfaces$If2.if2MethodNP()public abstract void ReflectInterfaces$If2.if2MethodTH() throws java.lang.Throwablepublic abstract void ReflectInterfaces$If2.if2MethodTH() throws java.lang.Throwable*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -