private static < T > boolean matches ( T tool , String moduleName ) { PrivilegedAction < Boolean > pa = ( ) -> { // for now, use reflection to implement // return moduleName.equals(tool.getClass().getModule().getName()); try { Method getModuleMethod = Class . class . getDeclaredMethod ( "getModule" ) ; Object toolModule = getModuleMethod . invoke ( tool . getClass ( ) ) ; Method getNameMethod = toolModule . getClass ( ) . getDeclaredMethod ( "getName" ) ; String toolModuleName = ( String ) getNameMethod . invoke ( toolModule ) ; return moduleName . equals ( toolModuleName ) ; } catch ( InvocationTargetException | NoSuchMethodException | IllegalAccessException e ) { return false ; } } ; return AccessController . doPrivileged ( pa ) ; }
Determine if this is the desired tool instance .