Package org.zkoss.lang.reflect
Class Fields
java.lang.Object
org.zkoss.lang.reflect.Fields
Utilities to access fields.
- Author:
- tomyeh
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final ObjectReturns the value of the specified public field or public method in the object.static final ObjectgetByCompound(Object obj, String name) Returns the value of the specified public field or public method of the object.static final voidSets the value of the specified public filed or public method in the object.static final voidsetAccessible(AccessibleObject f, boolean accessible) Changes the accessibility without throwing any exception.static final voidsetByCompound(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 final voidsetByCompound(Object obj, String name, Object val, boolean autoCoerce) Sets the value of the specified public field or public method in the object.
-
Constructor Details
-
Fields
public Fields()
-
-
Method Details
-
setAccessible
Changes the accessibility without throwing any exception.- Since:
- 3.0.3
-
getByCompound
Returns the value of the specified public field or public method of the object.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.
- Parameters:
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).- Throws:
NoSuchMethodException- if no corresponding field.
-
setByCompound
public static final void setByCompound(Object obj, String name, Object val, boolean autoCoerce) throws NoSuchMethodException Sets the value of the specified public field or public method in the object.- Parameters:
autoCoerce- whether to automatically convert val to the proper class that matches the argument of method or field.- Throws:
NoSuchMethodException
-
setByCompound
public static final void setByCompound(Object obj, String name, Object val) throws NoSuchMethodException Sets the value of the specified public field or public method in the object, without converting the specified val.It is a shortcut of setByCompound(obj, name, val, false).
- Parameters:
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).- Throws:
NoSuchMethodException
-
get
Returns the value of the specified public field or public method in the object. UnlikegetByCompound(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).- Throws:
NoSuchMethodException
-
set
public static final void set(Object obj, String name, Object val, boolean autoCoerce) throws NoSuchMethodException Sets the value of the specified public filed or public method in the object. UnlikesetByCompound(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).- Throws:
NoSuchMethodException
-