Class ClassUtils
java.lang.Object
nl.basjes.parse.useragent.utils.springframework.util.ClassUtils
Miscellaneous
java.lang.Class
utility methods.
Mainly for internal use within the framework.- Since:
- 1.1
- Author:
- Juergen Hoeller, Keith Donald, Rob Harrop, Sam Brannen see TypeUtils see ReflectionUtils
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
classPackageAsResourcePath
(Class<?> clazz) Given an input class object, return a string which consists of the class's package name as a pathname, i.e., all dots ('.') are replaced by slashes ('/').static Class<?>
forName
(String name, ClassLoader classLoader) Replacement forClass.forName()
that also returns Class instances for primitives (e.g.static ClassLoader
Return the default ClassLoader to use: typically the thread context ClassLoader, if available; the ClassLoader that loaded the ClassUtils class will be used as fallback.static Class<?>
Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for primitive classes.
-
Field Details
-
ARRAY_SUFFIX
Suffix for array class names:"[]"
.- See Also:
-
-
Method Details
-
getDefaultClassLoader
Return the default ClassLoader to use: typically the thread context ClassLoader, if available; the ClassLoader that loaded the ClassUtils class will be used as fallback.Call this method if you intend to use the thread context ClassLoader in a scenario where you clearly prefer a non-null ClassLoader reference: for example, for class path resource loading (but not necessarily for
Class.forName
, which accepts anull
ClassLoader reference as well).- Returns:
- the default ClassLoader (only
null
if even the system ClassLoader isn't accessible) see Thread#getContextClassLoader() see ClassLoader#getSystemClassLoader()
-
forName
public static Class<?> forName(String name, @Nullable ClassLoader classLoader) throws ClassNotFoundException, LinkageError Replacement forClass.forName()
that also returns Class instances for primitives (e.g. "int") and array class names (e.g. "String[]"). Furthermore, it is also capable of resolving nested class names in Java source style (e.g. "java.lang.Thread.State" instead of "java.lang.Thread$State").- Parameters:
name
- the name of the ClassclassLoader
- the class loader to use (may benull
, which indicates the default class loader)- Returns:
- a class instance for the supplied name
- Throws:
ClassNotFoundException
- if the class was not foundLinkageError
- if the class file could not be loaded see Class#forName(String, boolean, ClassLoader)
-
resolvePrimitiveClassName
Resolve the given class name as primitive class, if appropriate, according to the JVM's naming rules for primitive classes.Also supports the JVM's internal class names for primitive arrays. Does not support the "[]" suffix notation for primitive arrays; this is only supported by {link #forName(String, ClassLoader)}.
- Parameters:
name
- the name of the potentially primitive class- Returns:
- the primitive class, or
null
if the name does not denote a primitive class or primitive array class
-
classPackageAsResourcePath
Given an input class object, return a string which consists of the class's package name as a pathname, i.e., all dots ('.') are replaced by slashes ('/'). Neither a leading nor trailing slash is added. The result could be concatenated with a slash and the name of a resource and fed directly toClassLoader.getResource()
. For it to be fed toClass.getResource
instead, a leading slash would also have to be prepended to the returned value.- Parameters:
clazz
- the input class. Anull
value or the default (empty) package will result in an empty string ("") being returned.- Returns:
- a path which represents the package name see ClassLoader#getResource see Class#getResource
-