Package org.apache.commons.crypto.utils
Class ReflectionUtils
- java.lang.Object
-
- org.apache.commons.crypto.utils.ReflectionUtils
-
public final class ReflectionUtils extends java.lang.ObjectGeneral utility methods for working with reflection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classReflectionUtils.NegativeCacheSentinelA unique class which is used as a sentinel value in the caching for getClassByName.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.ClassLoader,java.util.Map<java.lang.String,java.lang.ref.WeakReference<java.lang.Class<?>>>>CACHE_CLASSESprivate static java.lang.ClassLoaderCLASSLOADERprivate static java.lang.Class<?>NEGATIVE_CACHE_SENTINELSentinel value to store negative cache results inCACHE_CLASSES.
-
Constructor Summary
Constructors Modifier Constructor Description privateReflectionUtils()The private constructor ofReflectionUtils.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Class<?>getClassByName(java.lang.String name)Loads a class by name.private static java.lang.Class<?>getClassByNameOrNull(java.lang.String name)Loads a class by name, returning null rather than throwing an exception if it couldn't be loaded.static <T> TnewInstance(java.lang.Class<T> klass, java.lang.Object... args)Uses the constructor represented by thisConstructorobject to create and initialize a new instance of the constructor's declaring class, with the specified initialization parameters.
-
-
-
Field Detail
-
CACHE_CLASSES
private static final java.util.Map<java.lang.ClassLoader,java.util.Map<java.lang.String,java.lang.ref.WeakReference<java.lang.Class<?>>>> CACHE_CLASSES
-
CLASSLOADER
private static final java.lang.ClassLoader CLASSLOADER
-
NEGATIVE_CACHE_SENTINEL
private static final java.lang.Class<?> NEGATIVE_CACHE_SENTINEL
Sentinel value to store negative cache results inCACHE_CLASSES.
-
-
Constructor Detail
-
ReflectionUtils
private ReflectionUtils()
The private constructor ofReflectionUtils.
-
-
Method Detail
-
getClassByName
public static java.lang.Class<?> getClassByName(java.lang.String name) throws java.lang.ClassNotFoundExceptionLoads a class by name.- Parameters:
name- the class name.- Returns:
- the class object.
- Throws:
java.lang.ClassNotFoundException- if the class is not found.
-
getClassByNameOrNull
private static java.lang.Class<?> getClassByNameOrNull(java.lang.String name)
Loads a class by name, returning null rather than throwing an exception if it couldn't be loaded. This is to avoid the overhead of creating an exception.- Parameters:
name- the class name.- Returns:
- the class object, or null if it could not be found.
-
newInstance
public static <T> T newInstance(java.lang.Class<T> klass, java.lang.Object... args)Uses the constructor represented by thisConstructorobject to create and initialize a new instance of the constructor's declaring class, with the specified initialization parameters.- Type Parameters:
T- type for the new instance- Parameters:
klass- the Class object.args- array of objects to be passed as arguments to the constructor call.- Returns:
- a new object created by calling the constructor this object represents.
-
-