Class MemberAccessors
java.lang.Object
org.linkki.util.reflection.accessor.MemberAccessors
Utility class to get easy access to the return value of member. In contrast to
PropertyAccessor, values of fields can also be read, in addition to the return value of
methods.
The implementation may use any performance optimization like caching of access code but never caches the returned value. Every call will retrieve the current value from the method or field.
-
Method Details
-
getValue
Retrieve the value from the given member (FieldorMethod) in the given object by calling the method or getting the value from the field. The returned value will directly be cast to the expected type. Note that this is always an unsafe cast!- Type Parameters:
T- the expected type of the return value- Parameters:
object- the object where to read the value fromfieldOrMethod- aFieldorMethodto access the value- Returns:
- the value retrieved by the
FieldorMethod - Throws:
IllegalArgumentException- if the field is not accessible or the value cannot be retrieved. The cause of the original exception is included.
-
getType
Deprecated.usegetType(Member, Type)instead to be able to handle generic types properlyReturns the type of the given member, either the type of the field, or the return type of the method.- Parameters:
fieldOrMethod- aFieldorMethodto access the value- Returns:
- the type of the member
- Throws:
IllegalArgumentException- if the given member is not a field or a method
-
getType
Returns the type of the given member, either the type of the field, or the return type of the method. The concreteclassis required to be able to handle generics types properly.- Parameters:
fieldOrMethod- aFieldorMethodto access the valueclazz- theclassthat contains the member- Returns:
- the type of the member
- Throws:
IllegalArgumentException- if the given member is not a field or a method, or if the Type can not be resolved
-
getType(Member, Type)instead to be able to handle generic types properly