public final class ClassUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ClassUtils.Copy
Namespace for Copy flags
|
| Modifier and Type | Field and Description |
|---|---|
static Object[] |
EMPTY_ARGS |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
copy(T obj)
Makes a copy of an object if possible or returns the object itself if copy is not supported
|
static <T> T |
copy(T obj,
int flags)
Makes a copy of an object if possible or returns null or self (depending on flags)
|
static <T> Constructor<T> |
findMatchingConstructor(Class<T> clazz,
int minParams,
Class<?>... parameterTypes)
copied from org.apache.commons.beanutils.ConstructorUtils since it's private there
|
static Object |
getFieldValue(Class<?> clazz,
Object object,
String property,
boolean includePrivateFields)
Retrieve a field value using reflection
|
static Object |
getFieldValue(Object object,
String property)
Retrieve a field value using reflection
The field accessor must be public
|
static String |
getImplemenationJarName(Class<?> clazz)
Returns the JAR name that contains the implementation of a specific class
|
static String |
getImplemenationJarName(String className)
Returns the JAR name that contains the implementation of a specific class
|
static Object |
getPrivateFieldValue(Object object,
String property)
Retrieve a field value using reflection
|
static Object |
invokeMethod(Class<?> clazz,
Object object,
String methodName,
Class<?>[] paramTypes,
Object[] paramValues,
boolean makeAccessible)
Invoke a method on an object using reflection
|
static Object |
invokeMethod(Object object,
Method method,
Object... params)
Invoke a method with parameters on an object
|
static Object |
invokeMethod(Object object,
String methodName,
Class<?> paramType,
Object paramValue)
Invokes a method with one parameter on an object using reflection
|
static Object |
invokeSimpleMethod(Class<?> clazz,
Object object,
String methodName,
boolean makeAccessible)
Invoke a simple method (without parameters) on an object using reflection
|
static Object |
invokeSimpleMethod(Object object,
Method method)
Invoke a simple method (without parameters) on an object
|
static Object |
invokeSimpleMethod(Object object,
String methodName)
Invoke a simple method (without parameters) on an object using reflection
|
static Object |
invokeSimplePrivateMethod(Object object,
String methodName)
Invoke a simple method (without parameters) on an object using reflection
|
static boolean |
isImmutableClass(Class<?> clazz)
Checks if a class is an immutable class such as a wrapper class of a primitive type
String and Class are also considered to be a immutable classes
|
static <T> T |
newInstance(Class<T> typeClass)
Creates a new Object instance
|
static <T> T |
newInstance(Class<T> typeClass,
Class<?> paramClass,
Object paramValue)
Creates a new Object instance with a single parameter constructor
|
static <T> T |
newInstance(Constructor<T> typeConstructor,
Object... params)
Creates a new Object instance
|
static void |
setPrivateFieldValue(Class<?> clazz,
Object object,
String property,
Object value)
Modifies a private field value using reflection
|
static void |
setPrivateFieldValue(Object object,
String property,
Object value)
Modifies a private field value using reflection
|
static <T> T |
testSerialization(Class<T> clazz,
T objToSerialize)
Used to test Serialization
|
public static final Object[] EMPTY_ARGS
public static <T> T testSerialization(Class<T> clazz, T objToSerialize)
T - the class typeclazz - class to serializeobjToSerialize - objedt to serializepublic static boolean isImmutableClass(Class<?> clazz)
clazz - the class to checkpublic static <T> T copy(T obj)
T - the class typeobj - the object to copypublic static <T> T copy(T obj,
int flags)
T - the class typeobj - the object to copyflags - options for the copypublic static Object getFieldValue(Class<?> clazz, Object object, String property, boolean includePrivateFields)
clazz - the class from which to obtain the fieldobject - the object instance from which to obtain the fieldproperty - the property to obtainincludePrivateFields - flag whether or not to include private fieldspublic static Object getFieldValue(Object object, String property)
object - the object instance from which to obtain the fieldproperty - the property to obtainpublic static Object getPrivateFieldValue(Object object, String property)
object - the object instance from which to obtain the fieldproperty - the property to obatinpublic static void setPrivateFieldValue(Class<?> clazz, Object object, String property, Object value)
clazz - the class of the objectobject - the object or null if static fields are to be changedproperty - the field namevalue - the field valuepublic static void setPrivateFieldValue(Object object, String property, Object value)
object - the object or null if static fields are to be changedproperty - the field namevalue - the field valuepublic static <T> T newInstance(Class<T> typeClass)
T - the class typetypeClass - the class of the object to instantiatepublic static <T> T newInstance(Class<T> typeClass, Class<?> paramClass, Object paramValue)
T - the type of the new objecttypeClass - the type of the object to instantiateparamClass - the type of the constructor parameterparamValue - the value of the constructor parameterpublic static <T> T newInstance(Constructor<T> typeConstructor, Object... params)
T - the type of the new objecttypeConstructor - the constructor of the object to instantiateparams - the constructor paramspublic static <T> Constructor<T> findMatchingConstructor(Class<T> clazz, int minParams, Class<?>... parameterTypes)
T - the class typeclazz - the class of the objectminParams - minimum number of paramsparameterTypes - the param typespublic static Object invokeMethod(Class<?> clazz, Object object, String methodName, Class<?>[] paramTypes, Object[] paramValues, boolean makeAccessible)
clazz - the class from which to obtain the fieldobject - the object instance on which to invoke the methodmethodName - the name of the method to invokeparamTypes - the list of parameter typesparamValues - the list of parameter valuesmakeAccessible - flag whether to make private methods accessiblepublic static Object invokeMethod(Object object, String methodName, Class<?> paramType, Object paramValue)
object - the object instance on which to invoke the methodmethodName - the name of the method to invokeparamType - the method parameter typeparamValue - the method parameter valuepublic static Object invokeSimpleMethod(Class<?> clazz, Object object, String methodName, boolean makeAccessible)
clazz - the class on which to invoke the methodobject - the object instance on which to invoke the methodmethodName - the name of the method to invokemakeAccessible - flag whether or not to make the method accessible (eg. if private)public static Object invokeSimpleMethod(Object object, String methodName)
object - the object instance on which to invoke the methodmethodName - the name of the method to invokepublic static Object invokeSimplePrivateMethod(Object object, String methodName)
object - the object instance on which to invoke the methodmethodName - the name of the method to invokepublic static Object invokeSimpleMethod(Object object, Method method)
object - the object on which to invoke the methodmethod - the methodpublic static Object invokeMethod(Object object, Method method, Object... params)
object - the object on which to invoke the methodmethod - the methodparams - the method paramspublic static String getImplemenationJarName(Class<?> clazz)
clazz - the classCopyright © 2008–2023 Apache Software Foundation. All rights reserved.