public static boolean isOverriddenMethod ( Method methodToFind , Class < ? > cls ) { Set < Class < ? > > superClasses = new HashSet <> ( ) ; for ( Class < ? > class1 : cls . getInterfaces ( ) ) { superClasses . add ( class1 ) ; } if ( cls . getSuperclass ( ) != null ) { superClasses . add ( cls . getSuperclass ( ) ) ; } for ( Class < ? > superClass : superClasses ) { if ( superClass != null && ! ( superClass . equals ( Object . class ) ) ) { for ( Method method : superClass . getMethods ( ) ) { if ( method . getName ( ) . equals ( methodToFind . getName ( ) ) && method . getReturnType ( ) . isAssignableFrom ( methodToFind . getReturnType ( ) ) && Arrays . equals ( method . getParameterTypes ( ) , methodToFind . getParameterTypes ( ) ) && ! Arrays . equals ( method . getGenericParameterTypes ( ) , methodToFind . getGenericParameterTypes ( ) ) ) { return true ; } } if ( isOverriddenMethod ( methodToFind , superClass ) ) { return true ; } } } return false ; }
Checks if the method methodToFind is the overridden method from the superclass or superinterface .