private static MethodHandle findMethod ( Class < ? > clazz , String methodName , boolean staticMethod , Class < ? > expectedReturnType , Class < ? > ... expectedParameterTypes ) { MethodHandle methodHandle = null ; try { Method method = clazz . getMethod ( methodName , expectedParameterTypes ) ; int modifiers = method . getModifiers ( ) ; Class < ? > returnType = method . getReturnType ( ) ; if ( Modifier . isStatic ( modifiers ) != staticMethod ) { throw new NoSuchMethodException ( ) ; } if ( expectedReturnType != null && ! expectedReturnType . isAssignableFrom ( returnType ) ) { throw new NoSuchMethodException ( ) ; } methodHandle = MethodHandles . publicLookup ( ) . unreflect ( method ) ; } catch ( NoSuchMethodException | SecurityException | IllegalAccessException e ) { // Method not found } return methodHandle ; }
Finds and returns a method handle for the given criteria .