public class Reflect extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends AccessibleObject> |
accessible(T accessible) |
<P> P |
as(Class<P> proxyType)
Create a proxy for the wrapped object allowing to typesafely invoke methods on it using a custom interface
|
Reflect |
call(String name)
Call a method by its name.
|
Reflect |
call(String name,
Object... args)
Call a method by its name.
|
Reflect |
create()
Call a constructor.
|
Reflect |
create(Object... args)
Call a constructor.
|
boolean |
equals(Object obj) |
Reflect |
field(String name)
Get a wrapped field.
|
Map<String,Reflect> |
fields() |
<T> T |
get()
Get the wrapped object
|
<T> T |
get(String name)
Get a field value.
|
Field |
getDeclaredField(Class<?> clazz,
String name) |
int |
hashCode() |
static Reflect |
on(Class<?> clazz) |
static Reflect |
on(Object object) |
static Reflect |
on(String name) |
Reflect |
set(String name,
Object value)
Set a field value.
|
String |
toString() |
Class<?> |
type()
Get the type of the wrapped object.
|
static Class<?> |
wrapper(Class<?> type)
Get a wrapper type for a primitive type, or the argument type itself, if it is not a primitive type.
|
public static Reflect on(String name) throws ReflectException
name - 类名ReflectException - Reflect异常public static <T extends AccessibleObject> T accessible(T accessible)
T - AccessibleObjectaccessible - The object to render accessiblepublic <T> T get()
T - A convenience generic parameter for automatic unsafe castingpublic Reflect set(String name, Object value) throws ReflectException
This is roughly equivalent to Field.set(Object, Object). If the wrapped object is a Class, then
this will set a value to a static member field. If the wrapped object is any other Object, then this will
set a value to an instance member field.
name - The field namevalue - The new field valueReflectException - If any reflection exception occurred.public <T> T get(String name) throws ReflectException
This is roughly equivalent to Field.get(Object). If the wrapped object is a Class, then this will
get a value from a static member field. If the wrapped object is any other Object, then this will get a
value from an instance member field.
If you want to "navigate" to a wrapped version of the field, use field(String) instead.
T - The field value Typename - The field nameReflectException - If any reflection exception occurred.field(String)public Field getDeclaredField(Class<?> clazz, String name) throws NoSuchFieldException
clazz - 类name - 字段名NoSuchFieldException - NoSuchFieldExceptionpublic Reflect field(String name) throws ReflectException
This is roughly equivalent to Field.get(Object). If the wrapped object is a Class, then this will
wrap a static member field. If the wrapped object is any other Object, then this wrap an instance member
field.
name - The field nameReflectException - If any reflection exception occurred.public Reflect call(String name) throws ReflectException
name - The method namevoid, to be used
for further reflection.ReflectException - If any reflection exception occurred.call(String, Object...)public Reflect call(String name, Object... args) throws ReflectException
name - The method nameargs - The method argumentsvoid, to be used
for further reflection.ReflectException - If any reflection exception occurred.public Reflect create() throws ReflectException
ReflectException - If any reflection exception occurred.create(Object...)public Reflect create(Object... args) throws ReflectException
args - The constructor argumentsReflectException - If any reflection exception occurred.public <P> P as(Class<P> proxyType)
proxyType - The interface type that is implemented by the proxypublic Class<?> type()
Object.getClass()Copyright © 2016. All rights reserved.