package com.test;import java.lang.reflect.Method;public class B extends A { @Override public void test1(int i) { System.out.println("B test1"); } public void test2() { System.out.println("B test2"); } public void test3() { System.out.println("B test3"); } public static void main(String[] args) { B b = new B(); Method[] bfs = b.getClass().getDeclaredMethods(); Method[] afs = b.getClass().getSuperclass().getDeclaredMethods(); for(Method bm : bfs) { for(Method am : afs) { if(bm.getName().equals(am.getName()) && bm.getReturnType().equals(am.getReturnType())) { Class[] bc = bm.getParameterTypes(); Class[] ac = am.getParameterTypes(); if(bc.length == ac.length) { boolean isEqual = true; for(int i=0;i<bc.length;i++) { if(!bc[i].equals(ac[i])) { isEqual = false; break; } } if(isEqual) { System.out.println(b.getClass()+" has method " + bm.getName() + " override " + b.getClass().getSuperclass()); } } } } } } }
package com.test;public class A { public int test1(int i) { System.out.println("A test1"); return 0; } public void test2() { System.out.println("A test2"); } }
package com.test;public class A { public void test1(int i) { System.out.println("A test1"); } public void test2() { System.out.println("A test2"); } }
@Override
public void test1(int i) {
System.out.println("B test1");
}
public void test2() {
System.out.println("B test2");
}
public void test3() {
System.out.println("B test3");
}
public static void main(String[] args) {
B b = new B();
Method[] bfs = b.getClass().getDeclaredMethods();
Method[] afs = b.getClass().getSuperclass().getDeclaredMethods();
for(Method bm : bfs) {
for(Method am : afs) {
if(bm.getName().equals(am.getName()) &&
bm.getReturnType().equals(am.getReturnType())) {
Class[] bc = bm.getParameterTypes();
Class[] ac = am.getParameterTypes();
if(bc.length == ac.length) {
boolean isEqual = true;
for(int i=0;i<bc.length;i++) {
if(!bc[i].equals(ac[i])) {
isEqual = false;
break;
}
}
if(isEqual) {
System.out.println(b.getClass()+" has method " + bm.getName() +
" override " + b.getClass().getSuperclass());
}
}
}
}
}
}
}
public int test1(int i) {
System.out.println("A test1");
return 0;
}
public void test2() {
System.out.println("A test2");
}
}
public void test1(int i) {
System.out.println("A test1");
}
public void test2() {
System.out.println("A test2");
}
}