Package org.apache.commons.crypto.utils
Class ReflectionUtils
java.lang.Object
org.apache.commons.crypto.utils.ReflectionUtils
General utility methods for working with reflection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
A unique class which is used as a sentinel value in the caching for getClassByName. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map
<ClassLoader, Map<String, WeakReference<Class<?>>>> private static final ClassLoader
private static final Class
<?> Sentinel value to store negative cache results inCACHE_CLASSES
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class
<?> getClassByName
(String name) Loads a class by name.private static Class
<?> getClassByNameOrNull
(String name) Loads a class by name, returning null rather than throwing an exception if it couldn't be loaded.static <T> T
newInstance
(Class<T> klass, Object... args) Uses the constructor represented by thisConstructor
object to create and initialize a new instance of the constructor's declaring class, with the specified initialization parameters.
-
Field Details
-
CACHE_CLASSES
-
CLASSLOADER
-
NEGATIVE_CACHE_SENTINEL
Sentinel value to store negative cache results inCACHE_CLASSES
.
-
-
Constructor Details
-
ReflectionUtils
private ReflectionUtils()The private constructor ofReflectionUtils
.
-
-
Method Details
-
getClassByName
Loads a class by name.- Parameters:
name
- the class name.- Returns:
- the class object.
- Throws:
ClassNotFoundException
- if the class is not found.
-
getClassByNameOrNull
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
Uses the constructor represented by thisConstructor
object 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.
-