public class Fields extends Object
| Constructor and Description |
|---|
Fields() |
| Modifier and Type | Method and Description |
|---|---|
static Object |
get(Object obj,
String name)
Returns the value of the specified public field or public method
in the object.
|
static Object |
getByCompound(Object obj,
String name)
Returns the value of the specified public field or public
method of the object.
|
static void |
set(Object obj,
String name,
Object val,
boolean autoCoerce)
Sets the value of the specified public filed or public method
in the object.
|
static void |
setAccessible(AccessibleObject f,
boolean accessible)
Changes the accessibility without throwing any exception.
|
static void |
setByCompound(Object obj,
String name,
Object val)
Sets the value of the specified public field or public method
in the object, without converting the specified val.
|
static void |
setByCompound(Object obj,
String name,
Object val,
boolean autoCoerce)
Sets the value of the specified public field or public
method in the object.
|
public static final void setAccessible(AccessibleObject f, boolean accessible)
public static final Object getByCompound(Object obj, String name) throws NoSuchMethodException
If getByCompound(obj, "a.b.c") is called and obj.getA() or obj.getA().getB() returns null, the result is null. However, NullPointerException is thrown if obj is null.
name - the field name. It can be in form of "a.b.c", but cannot
be an expression.
It must be a public field or public method (prefixed with set).NoSuchMethodException - if no corresponding field.public static final void setByCompound(Object obj, String name, Object val, boolean autoCoerce) throws NoSuchMethodException
autoCoerce - whether to automatically convert val to the proper
class that matches the argument of method or field.NoSuchMethodExceptionpublic static final void setByCompound(Object obj, String name, Object val) throws NoSuchMethodException
It is a shortcut of setByCompound(obj, name, val, false).
name - the field name. It can be in form of "a.b.c", but cannot
be an expression.
It must be a public field or public method (prefixed with set).NoSuchMethodExceptionpublic static final Object get(Object obj, String name) throws NoSuchMethodException
getByCompound(java.lang.Object, java.lang.String), name cannot contain '.'.
In other words, it must be the name of a public field
or method (prefixed with get).NoSuchMethodExceptionpublic static final void set(Object obj, String name, Object val, boolean autoCoerce) throws NoSuchMethodException
setByCompound(java.lang.Object, java.lang.String, java.lang.Object, boolean), name cannot contain '.'.
In other words, it must be the name of a public field
or method (prefixed with set).NoSuchMethodExceptionCopyright © 2018. All rights reserved.