rip*_*234 7 java reflection methods
帮助我使这个方法更加坚实:
/**
* Check if the method is declared in the interface.
* Assumes the method was obtained from a concrete class that
* implements the interface, and return true if the method overrides
* a method from the interface.
*/
public static boolean isDeclaredInInterface(Method method, Class<?> interfaceClass) {
for (Method methodInInterface : interfaceClass.getMethods())
{
if (methodInInterface.getName().equals(method.getName()))
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
Yis*_*hai 10
这个怎么样:
try {
interfaceClass.getMethod(method.getName(), method.getParameterTypes());
return true;
} catch (NoSuchMethodException e) {
return false;
}
Run Code Online (Sandbox Code Playgroud)