public final class ClassUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ClassUtils.Copy
Namespace for Copy flags
|
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 Object |
getPrivateFieldValue(Object object,
String property)
Retrieve a field value using reflection
|
static Object |
invokeSimpleMethod(Class<?> clazz,
Object object,
String methodName,
boolean includePrivateMethods)
Invoke a simple method (without parameters) on an object using reflection
|
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 void |
setPrivateFieldValue(Class<?> clazz,
Object object,
String property,
Object value)
Retrieve a field value using reflection
|
static <T> T |
testSerialization(Class<T> clazz,
T objToSerialize)
Used to test Serialization
|
public static <T> T testSerialization(Class<T> clazz, T objToSerialize)
T
- the class typeclazz
- class to serializeobjToSerialize
- objedt to serializepublic 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 <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 invokeSimpleMethod(Class<?> clazz, Object object, String methodName, boolean includePrivateMethods)
clazz
- the class from which to obtain the fieldobject
- the object instance on which to invoke the methodmethodName
- the name of the method to invokeincludePrivateMethods
- flag whether or not to include private methodspublic 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 invokeCopyright © 2008–2023 Apache Software Foundation. All rights reserved.