public static Class < ? > forName ( String name , ClassLoader classLoader ) throws ClassNotFoundException , LinkageError { Assert . notNull ( name , "Name must not be null" ) ; Class < ? > clazz = resolvePrimitiveClassName ( name ) ; if ( clazz == null ) { clazz = commonClassCache . get ( name ) ; } if ( clazz != null ) { return clazz ; } if ( name . endsWith ( ARRAY_SUFFIX ) ) { String elementClassName = name . substring ( 0 , name . length ( ) - ARRAY_SUFFIX . length ( ) ) ; Class < ? > elementClass = forName ( elementClassName , classLoader ) ; return Array . newInstance ( elementClass , 0 ) . getClass ( ) ; } if ( name . startsWith ( NON_PRIMITIVE_ARRAY_PREFIX ) && name . endsWith ( ";" ) ) { String elementName = name . substring ( NON_PRIMITIVE_ARRAY_PREFIX . length ( ) , name . length ( ) - 1 ) ; Class < ? > elementClass = forName ( elementName , classLoader ) ; return Array . newInstance ( elementClass , 0 ) . getClass ( ) ; } if ( name . startsWith ( INTERNAL_ARRAY_PREFIX ) ) { String elementName = name . substring ( INTERNAL_ARRAY_PREFIX . length ( ) ) ; Class < ? > elementClass = forName ( elementName , classLoader ) ; return Array . newInstance ( elementClass , 0 ) . getClass ( ) ; } ClassLoader classLoaderToUse = classLoader ; if ( classLoaderToUse == null ) { classLoaderToUse = getDefaultClassLoader ( ) ; } try { return classLoaderToUse . loadClass ( name ) ; } catch ( ClassNotFoundException ex ) { int lastDotIndex = name . lastIndexOf ( '.' ) ; if ( lastDotIndex != - 1 ) { String innerClassName = name . substring ( 0 , lastDotIndex ) + '$' + name . substring ( lastDotIndex + 1 ) ; try { return classLoaderToUse . loadClass ( innerClassName ) ; } catch ( ClassNotFoundException ex2 ) { } } throw ex ; } }
Replacement for < code > Class.forName ( ) < /code > that also returns Class instances for primitives ( e.g . `` int '' ) and array class names ( e.g . `` String [ ] '' ) . Furthermore , it is also capable of resolving inner class names in Java source style ( e.g . `` java.lang.Thread.State '' instead of `` java.lang.Thread $ State '' ) .