public class ReflectionUtils extends ReflectionMethodUtils
限定符和类型 | 类和说明 |
---|---|
static interface |
ReflectionUtils.FieldCallback
Callback interface invoked on each field in the hierarchy.
|
static interface |
ReflectionUtils.FieldFilter
Callback optionally used to filter fields to be operated on by a field callback.
|
ReflectionMethodUtils.MethodCallback, ReflectionMethodUtils.MethodFilter
限定符和类型 | 字段和说明 |
---|---|
static ReflectionUtils.FieldFilter |
COPYABLE_FIELDS
Pre-built FieldFilter that matches all non-static, non-final fields.
|
NON_BRIDGED_METHODS, USER_DECLARED_METHODS
构造器和说明 |
---|
ReflectionUtils() |
限定符和类型 | 方法和说明 |
---|---|
static void |
doWithFields(Class<?> clazz,
ReflectionUtils.FieldCallback fc)
Invoke the given callback on all fields in the target class, going up the
class hierarchy to get all declared fields.
|
static void |
doWithFields(Class<?> clazz,
ReflectionUtils.FieldCallback fc,
ReflectionUtils.FieldFilter ff)
Invoke the given callback on all fields in the target class, going up the
class hierarchy to get all declared fields.
|
static void |
fieldCloneByInherit(Object parentSource,
Object dest)
Given the source object and the destination, which must be the same class
or a subclass, copy all fields, including inherited fields.
|
static void |
fieldCloneByName(Map<String,Object> sourceMap,
Object target) |
static void |
fieldCloneByName(Object source,
Object target)
两个对象属性的拷贝:将source对象的属性值,赋值给target对象对应的名字和类型相同的属性。
|
static Field |
findField(Class<?> clazz,
String name)
|
static Field |
findField(Class<?> clazz,
String name,
Class<?> type)
|
static Map<String,Field> |
getAllFields(Class<?> clazz)
Get all fields.
|
static Map<String,Field> |
getAllNonStaticFields(Class<?> clazz) |
static Object |
getField(Field field,
Object target)
Get the field represented by the supplied
field object on the
specified target object . |
static boolean |
isPublicStaticFinal(Field field)
Determine whether the given field is a "public static final" constant.
|
static void |
makeAccessible(Constructor<?> ctor)
Make the given constructor accessible, explicitly setting it accessible
if necessary.
|
static void |
makeAccessible(Field field)
Make the given field accessible, explicitly setting it accessible if
necessary.
|
static void |
makeAccessible(Method method)
Make the given method accessible, explicitly setting it accessible if
necessary.
|
static <T> T |
newInstance(Class<T> clazz)
a slient way to invoke the class.newInstance() method.
|
static void |
setField(Field field,
Object target,
Object value)
Set the field represented by the supplied
field object on the
specified target object to the specified value . |
static Map<String,Object> |
toMap(Object source) |
declaresException, doWithMethods, doWithMethods, findMethod, getAllDeclaredMethods, getConstructor, getDeclaredConstructor, getDeclaredMethod, getMethod, getQualifiedMethodName, getStaticMethod, getUniqueDeclaredMethods, invokeConstructor, invokeConstructor, invokeMethod, invokeMethod, invokeMethod, invokeStaticMethod, invokeStaticMethod, isEqualsMethod, isHashCodeMethod, isObjectMethod, isToStringMethod
public static final ReflectionUtils.FieldFilter COPYABLE_FIELDS
public static <T> T newInstance(Class<T> clazz)
public static void setField(Field field, Object target, Object value)
field object
on the
specified target object
to the specified value
.
In accordance with Field.set(Object, Object)
semantics, the new value
is automatically unwrapped if the underlying field has a primitive type.
Thrown exceptions are handled via a call to #handleReflectionException(Exception)
.
field
- the field to settarget
- the target object on which to set the fieldvalue
- the value to set; may be null
public static Object getField(Field field, Object target)
field object
on the
specified target object
. In accordance with Field.get(Object)
semantics, the returned value is automatically wrapped if the underlying field
has a primitive type.
Thrown exceptions are handled via a call to #handleReflectionException(Exception)
.
field
- the field to gettarget
- the target object from which to get the fieldpublic static boolean isPublicStaticFinal(Field field)
field
- the field to checkpublic static void makeAccessible(Field field)
setAccessible(true)
method is only called
when actually necessary, to avoid unnecessary conflicts with a JVM
SecurityManager (if active).field
- the field to make accessibleAccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean)
public static void makeAccessible(Method method)
setAccessible(true)
method is only called
when actually necessary, to avoid unnecessary conflicts with a JVM
SecurityManager (if active).method
- the method to make accessibleAccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean)
public static void makeAccessible(Constructor<?> ctor)
setAccessible(true)
method is only called
when actually necessary, to avoid unnecessary conflicts with a JVM
SecurityManager (if active).ctor
- the constructor to make accessibleAccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean)
public static void fieldCloneByInherit(Object parentSource, Object dest)
IllegalArgumentException
- if the arguments are incompatiblepublic static void fieldCloneByName(Object source, Object target)
支持数值类型 把小范围的值 赋值给 大范围的值,比如Float赋值给Double
source
- 原始对象[orginal obj]target
- 目标对象[target obj]public static Map<String,Field> getAllFields(Class<?> clazz)
Object
.clazz
- the class to introspectpublic static Field findField(Class<?> clazz, String name)
field
on the supplied Class
with the
supplied name
. Searches all superclasses up to Object
.clazz
- the class to introspectname
- the name of the fieldnull
if not foundpublic static Field findField(Class<?> clazz, String name, Class<?> type)
field
on the supplied Class
with the
supplied name
and/or type
. Searches all superclasses
up to Object
.clazz
- the class to introspectname
- the name of the field (may be null
if type is specified)type
- the type of the field (may be null
if name is specified)null
if not foundpublic static void doWithFields(Class<?> clazz, ReflectionUtils.FieldCallback fc)
clazz
- the target class to analyzefc
- the callback to invoke for each fieldpublic static void doWithFields(Class<?> clazz, ReflectionUtils.FieldCallback fc, ReflectionUtils.FieldFilter ff)
clazz
- the target class to analyzefc
- the callback to invoke for each fieldff
- the filter that determines the fields to apply the callback toCopyright © 2018 jretty-org. All rights reserved.