public static void forceLoad ( final Class type ) { if ( type == null ) throw new NullArgumentException ( "type" ) ; // don't attempt to force primitives to load if ( type . isPrimitive ( ) ) return ; // don't attempt to force java.* classes to load String packageName = Classes . getPackageName ( type ) ; // System.out.println("package name: " + packageName); if ( packageName . startsWith ( "java." ) || packageName . startsWith ( "javax." ) ) { return ; } // System.out.println("forcing class to load: " + type); try { Method methods [ ] = type . getDeclaredMethods ( ) ; Method method = null ; for ( int i = 0 ; i < methods . length ; i ++ ) { int modifiers = methods [ i ] . getModifiers ( ) ; if ( Modifier . isStatic ( modifiers ) ) { method = methods [ i ] ; break ; } } if ( method != null ) { method . invoke ( null , ( Object [ ] ) null ) ; } else { type . newInstance ( ) ; } } catch ( Exception ignore ) { ThrowableHandler . add ( ignore ) ; } }
Force the given class to be loaded fully .