@ SuppressWarnings ( "unchecked" ) public static < T > T invoke ( Method method ) { boolean forceAccess = false ; try { if ( ! method . isAccessible ( ) ) { method . setAccessible ( true ) ; forceAccess = true ; } return ( T ) method . invoke ( null ) ; } catch ( InvocationTargetException | IllegalAccessException ex ) { throw new ReflectionException ( ex ) ; } finally { if ( forceAccess ) { method . setAccessible ( false ) ; } } }
Invoke the static method without any arguments .