Package org.linkki.util
Class MemberAccessors
- java.lang.Object
-
- org.linkki.util.MemberAccessors
-
public class MemberAccessors extends Object
Utility class to get easy access to the return value of a method or the current object of a field. Simply usegetValue(Object, Member).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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> TgetValue(Object object, Member fieldOrMethod)StringtoString()
-
-
-
Method Detail
-
getValue
public static <T> T getValue(Object object, Member fieldOrMethod)
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.
-
-