@@ -89,135 +89,6 @@ private ClassUtils() {
8989
9090 // -- Class loading, querying and reflection --
9191
92- /**
93- * Loads the class with the given name, using the current thread's context
94- * class loader, or null if it cannot be loaded.
95- *
96- * @param name The name of the class to load.
97- * @return The loaded class, or null if the class could not be loaded.
98- * @see #loadClass(String, ClassLoader, boolean)
99- */
100- public static Class <?> loadClass (final String name ) {
101- return loadClass (name , null , true );
102- }
103-
104- /**
105- * Loads the class with the given name, using the specified
106- * {@link ClassLoader}, or null if it cannot be loaded.
107- *
108- * @param name The name of the class to load.
109- * @param classLoader The class loader with which to load the class; if null,
110- * the current thread's context class loader will be used.
111- * @return The loaded class, or null if the class could not be loaded.
112- * @see #loadClass(String, ClassLoader, boolean)
113- */
114- public static Class <?> loadClass (final String name ,
115- final ClassLoader classLoader )
116- {
117- return loadClass (name , classLoader , true );
118- }
119-
120- /**
121- * Loads the class with the given name, using the current thread's context
122- * class loader.
123- *
124- * @param className the name of the class to load
125- * @param quietly Whether to return {@code null} (rather than throwing
126- * {@link IllegalArgumentException}) if something goes wrong loading
127- * the class
128- * @return The loaded class, or {@code null} if the class could not be loaded
129- * and the {@code quietly} flag is set.
130- * @see #loadClass(String, ClassLoader, boolean)
131- * @throws IllegalArgumentException If the class cannot be loaded and the
132- * {@code quietly} flag is not set.
133- */
134- public static Class <?> loadClass (final String className ,
135- final boolean quietly )
136- {
137- return loadClass (className , null , quietly );
138- }
139-
140- /**
141- * Loads the class with the given name, using the specified
142- * {@link ClassLoader}, or null if it cannot be loaded.
143- * <p>
144- * This method is capable of parsing several different class name syntaxes. In
145- * particular, array classes (including primitives) represented using either
146- * square brackets or internal Java array name syntax are supported. Examples:
147- * </p>
148- * <ul>
149- * <li>{@code boolean} is loaded as {@code boolean.class}</li>
150- * <li>{@code Z} is loaded as {@code boolean.class}</li>
151- * <li>{@code double[]} is loaded as {@code double[].class}</li>
152- * <li>{@code string[]} is loaded as {@code java.lang.String.class}</li>
153- * <li>{@code [F} is loaded as {@code float[].class}</li>
154- * </ul>
155- *
156- * @param name The name of the class to load.
157- * @param classLoader The class loader with which to load the class; if null,
158- * the current thread's context class loader will be used.
159- * @param quietly Whether to return {@code null} (rather than throwing
160- * {@link IllegalArgumentException}) if something goes wrong loading
161- * the class
162- * @return The loaded class, or {@code null} if the class could not be loaded
163- * and the {@code quietly} flag is set.
164- * @throws IllegalArgumentException If the class cannot be loaded and the
165- * {@code quietly} flag is not set.
166- */
167- public static Class <?> loadClass (final String name ,
168- final ClassLoader classLoader , final boolean quietly )
169- {
170- // handle primitive types
171- if (name .equals ("Z" ) || name .equals ("boolean" )) return boolean .class ;
172- if (name .equals ("B" ) || name .equals ("byte" )) return byte .class ;
173- if (name .equals ("C" ) || name .equals ("char" )) return char .class ;
174- if (name .equals ("D" ) || name .equals ("double" )) return double .class ;
175- if (name .equals ("F" ) || name .equals ("float" )) return float .class ;
176- if (name .equals ("I" ) || name .equals ("int" )) return int .class ;
177- if (name .equals ("J" ) || name .equals ("long" )) return long .class ;
178- if (name .equals ("S" ) || name .equals ("short" )) return short .class ;
179- if (name .equals ("V" ) || name .equals ("void" )) return void .class ;
180-
181- // handle built-in class shortcuts
182- final String className ;
183- if (name .equals ("string" )) className = "java.lang.String" ;
184- else className = name ;
185-
186- // handle source style arrays (e.g.: "java.lang.String[]")
187- if (name .endsWith ("[]" )) {
188- final String elementClassName = name .substring (0 , name .length () - 2 );
189- return Types .array (loadClass (elementClassName , classLoader ));
190- }
191-
192- // handle non-primitive internal arrays (e.g.: "[Ljava.lang.String;")
193- if (name .startsWith ("[L" ) && name .endsWith (";" )) {
194- final String elementClassName = name .substring (2 , name .length () - 1 );
195- return Types .array (loadClass (elementClassName , classLoader ));
196- }
197-
198- // handle other internal arrays (e.g.: "[I", "[[I", "[[Ljava.lang.String;")
199- if (name .startsWith ("[" )) {
200- final String elementClassName = name .substring (1 );
201- return Types .array (loadClass (elementClassName , classLoader ));
202- }
203-
204- // load the class!
205- try {
206- final ClassLoader cl =
207- classLoader == null ? Thread .currentThread ().getContextClassLoader ()
208- : classLoader ;
209- return cl .loadClass (className );
210- }
211- catch (final Throwable t ) {
212- // NB: Do not allow any failure to load the class to crash us.
213- // Not ClassNotFoundException.
214- // Not NoClassDefFoundError.
215- // Not UnsupportedClassVersionError!
216- if (quietly ) return null ;
217- throw new IllegalArgumentException ("Cannot load class: " + className , t );
218- }
219- }
220-
22192 /** Checks whether a class with the given name exists. */
22293 public static boolean hasClass (final String className ) {
22394 return hasClass (className , null );
@@ -724,6 +595,38 @@ private static <T extends AnnotatedElement> void populateCache(
724595
725596 // -- Deprecated methods --
726597
598+ /** @deprecated Use {@link Types#load(String)} instead. */
599+ @ Deprecated
600+ public static Class <?> loadClass (final String name ) {
601+ return Types .load (name );
602+ }
603+
604+ /** @deprecated Use {@link Types#load(String, ClassLoader)} instead. */
605+ @ Deprecated
606+ public static Class <?> loadClass (final String name ,
607+ final ClassLoader classLoader )
608+ {
609+ return Types .load (name , classLoader );
610+ }
611+
612+ /** @deprecated Use {@link Types#load(String, boolean)} instead. */
613+ @ Deprecated
614+ public static Class <?> loadClass (final String className ,
615+ final boolean quietly )
616+ {
617+ return Types .load (className , quietly );
618+ }
619+
620+ /**
621+ * @deprecated Use {@link Types#load(String, ClassLoader, boolean)} instead.
622+ */
623+ @ Deprecated
624+ public static Class <?> loadClass (final String name ,
625+ final ClassLoader classLoader , final boolean quietly )
626+ {
627+ return Types .load (name , classLoader , quietly );
628+ }
629+
727630 /** @deprecated use {@link ConversionUtils#convert(Object, Class)} */
728631 @ Deprecated
729632 public static <T > T convert (final Object value , final Class <T > type ) {
0 commit comments