类 FieldUtils
- java.lang.Object
-
- io.microsphere.util.BaseUtils
-
- io.microsphere.reflect.FieldUtils
-
-
构造器概要
构造器 构造器 说明 FieldUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static void
assertFieldMatchType(java.lang.Object instance, java.lang.String fieldName, java.lang.Class<?> expectedType)
Assert Field type matchstatic java.util.Set<java.lang.reflect.Field>
findAllDeclaredFields(java.lang.Class<?> declaredClass, java.util.function.Predicate<java.lang.reflect.Field>... fieldFilters)
static java.util.Set<java.lang.reflect.Field>
findAllFields(java.lang.Class<?> declaredClass, java.util.function.Predicate<java.lang.reflect.Field>... fieldFilters)
static java.lang.reflect.Field
findField(java.lang.Class<?> klass, java.lang.String fieldName)
Find the declaredField
by its' namestatic java.lang.reflect.Field
findField(java.lang.Class<?> klass, java.lang.String fieldName, java.lang.Class<?> fieldType)
Find the declaredField
by its' namestatic java.lang.reflect.Field
findField(java.lang.Class<?> klass, java.lang.String fieldName, java.util.function.Predicate<java.lang.reflect.Field>... predicates)
Find the declaredField
by its' namestatic java.lang.reflect.Field
findField(java.lang.Object object, java.lang.String fieldName)
Find the specified objects' declaredField
by its' namestatic java.lang.reflect.Field
getDeclaredField(java.lang.Class<?> declaredClass, java.lang.String fieldName)
Like theClass.getDeclaredField(String)
method without throwing anyException
static <V> V
getFieldValue(java.lang.Object instance, java.lang.reflect.Field field)
Get the value of the specifiedField
static <V> V
getFieldValue(java.lang.Object instance, java.lang.String fieldName)
Get the value of the specifiedField
static <V> V
getFieldValue(java.lang.Object instance, java.lang.String fieldName, java.lang.Class<V> fieldType)
GetField
Valuestatic <V> V
getFieldValue(java.lang.Object instance, java.lang.String fieldName, V defaultValue)
GetField
Valuestatic <T> T
getStaticFieldValue(java.lang.Class<?> klass, java.lang.String fieldName)
Get the staticField
Valuestatic <T> T
getStaticFieldValue(java.lang.reflect.Field field)
Get the staticField
Valuestatic <V> V
setFieldValue(java.lang.Object instance, java.lang.reflect.Field field, V value)
Set the value for the specifiedField
static <V> V
setFieldValue(java.lang.Object instance, java.lang.String fieldName, V value)
Set the value for the specifiedField
static void
setStaticFieldValue(java.lang.Class<?> klass, java.lang.String fieldName, java.lang.Object fieldValue)
Set the value to staticField
-
-
-
方法详细资料
-
findField
public static java.lang.reflect.Field findField(java.lang.Object object, java.lang.String fieldName)
Find the specified objects' declaredField
by its' name- 参数:
object
- theobject
to findfieldName
- the name offield
- 返回:
- null if not found
-
findField
public static java.lang.reflect.Field findField(java.lang.Class<?> klass, java.lang.String fieldName)
Find the declaredField
by its' name- 参数:
klass
-class
to findfieldName
- the name offield
- 返回:
- null if not found
-
findField
public static java.lang.reflect.Field findField(java.lang.Class<?> klass, java.lang.String fieldName, java.lang.Class<?> fieldType)
Find the declaredField
by its' name- 参数:
klass
-class
to findfieldName
- the name offield
fieldType
- thetype
offield
- 返回:
- null if not found
-
findField
public static java.lang.reflect.Field findField(java.lang.Class<?> klass, java.lang.String fieldName, java.util.function.Predicate<java.lang.reflect.Field>... predicates)
Find the declaredField
by its' name- 参数:
klass
-class
to findfieldName
- the name offield
predicates
- zero or morePredicate
- 返回:
- null if not found
-
getStaticFieldValue
public static <T> T getStaticFieldValue(java.lang.Class<?> klass, java.lang.String fieldName)
Get the staticField
Value- 参数:
klass
-class
to findfieldName
- the name offield
- 返回:
null
iffield
isnull
or get failed
-
getStaticFieldValue
public static <T> T getStaticFieldValue(java.lang.reflect.Field field)
Get the staticField
Value- 参数:
field
-Field
- 返回:
null
iffield
isnull
or get failed
-
setStaticFieldValue
public static void setStaticFieldValue(java.lang.Class<?> klass, java.lang.String fieldName, java.lang.Object fieldValue)
Set the value to staticField
- 参数:
klass
- the class declared the fieldfieldName
- the name ofField
fieldValue
- the value ofField
-
findAllFields
public static java.util.Set<java.lang.reflect.Field> findAllFields(java.lang.Class<?> declaredClass, java.util.function.Predicate<java.lang.reflect.Field>... fieldFilters)
-
findAllDeclaredFields
public static java.util.Set<java.lang.reflect.Field> findAllDeclaredFields(java.lang.Class<?> declaredClass, java.util.function.Predicate<java.lang.reflect.Field>... fieldFilters)
-
getDeclaredField
public static java.lang.reflect.Field getDeclaredField(java.lang.Class<?> declaredClass, java.lang.String fieldName)
Like theClass.getDeclaredField(String)
method without throwing anyException
- 参数:
declaredClass
- the declared classfieldName
- the name ofField
- 返回:
- if can't be found, return
null
-
getFieldValue
public static <V> V getFieldValue(java.lang.Object instance, java.lang.String fieldName) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
Get the value of the specifiedField
- 参数:
instance
- the instance whose field should be modifiedfieldName
- the name ofField
- 返回:
- the value of the specified
Field
- 抛出:
java.lang.IllegalStateException
- if this Field object is enforcing Java language access control and the underlying field is inaccessible.java.lang.IllegalArgumentException
- if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof).
-
getFieldValue
public static <V> V getFieldValue(java.lang.Object instance, java.lang.String fieldName, V defaultValue) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
GetField
Value- 类型参数:
V
- field type- 参数:
instance
- the instance whose field should be modifiedfieldName
- field namedefaultValue
- default value- 返回:
Field
Value- 抛出:
java.lang.IllegalStateException
- if this Field object is enforcing Java language access control and the underlying field is inaccessible.java.lang.IllegalArgumentException
- if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof).
-
getFieldValue
public static <V> V getFieldValue(java.lang.Object instance, java.lang.String fieldName, java.lang.Class<V> fieldType) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
GetField
Value- 类型参数:
V
- field type- 参数:
instance
- the instance whose field should be modifiedfieldName
- field namefieldType
- field type- 返回:
Field
Value- 抛出:
java.lang.IllegalStateException
- if this Field object is enforcing Java language access control and the underlying field is inaccessible.java.lang.IllegalArgumentException
- if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof).
-
getFieldValue
public static <V> V getFieldValue(java.lang.Object instance, java.lang.reflect.Field field) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
Get the value of the specifiedField
- 参数:
instance
- the instance whose field should be modifiedfield
-Field
- 返回:
- the value of the specified
Field
- 抛出:
java.lang.IllegalStateException
- if this Field object is enforcing Java language access control and the underlying field is inaccessible.java.lang.IllegalArgumentException
- if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof).
-
setFieldValue
public static <V> V setFieldValue(java.lang.Object instance, java.lang.String fieldName, V value) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
Set the value for the specifiedField
- 参数:
instance
- the instance whose field should be modifiedfieldName
- the name ofField
value
- the value of field to be set- 返回:
- the previous value of the specified
Field
- 抛出:
java.lang.IllegalStateException
- if this Field object is enforcing Java language access control and the underlying field is inaccessible.java.lang.IllegalArgumentException
- if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof).
-
setFieldValue
public static <V> V setFieldValue(java.lang.Object instance, java.lang.reflect.Field field, V value) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
Set the value for the specifiedField
- 参数:
instance
- the instance whose field should be modifiedfield
-Field
value
- the value of field to be set- 返回:
- the previous value of the specified
Field
- 抛出:
java.lang.IllegalStateException
- if this Field object is enforcing Java language access control and the underlying field is inaccessible.java.lang.IllegalArgumentException
- if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof).
-
assertFieldMatchType
public static void assertFieldMatchType(java.lang.Object instance, java.lang.String fieldName, java.lang.Class<?> expectedType) throws java.lang.IllegalArgumentException
Assert Field type match- 参数:
instance
- ObjectfieldName
- field nameexpectedType
- expected type- 抛出:
java.lang.IllegalArgumentException
- if type is not matched
-
-