Interface FieldAccessor
- All Superinterfaces:
BaseAccessor<Field>
- All Known Implementing Classes:
BareAccessorFactory.BareFieldAccessor,MethodHandleAccessorFactory.MethodHandleFieldAccessor
An accessor which wraps a java.lang.reflect Field and makes it much easier to read/write from/to it.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescription<T> @NotNull Result<T> getValue()Gets the value of the wrapped field using the instance the reflexion object which created this instance is bound to (but only if the field is not static).<T> @NotNull Result<T> Gets the value of the wrapped field using the given instance.Sets the value of the wrapped field using the instance the reflexion object which created this instance is bound to (but only if the field is not static).Sets the value of the wrapped field in the given object instance.Methods inherited from interface dev.derklaro.reflexion.BaseAccessor
getMember, getReflexion
-
Method Details
-
getValue
Gets the value of the wrapped field using the instance the reflexion object which created this instance is bound to (but only if the field is not static). This method never throws an exception, all exceptions are given back to the caller in the returned result instance.- Type Parameters:
T- the type of the data returned from the field.- Returns:
- the result of the get operation, either holding the field value or a read exception.
-
getValue
Gets the value of the wrapped field using the given instance. This method never throws an exception, all exceptions are given back to the caller in the returned result instance.The given instance should be present in case the field is not static, and the associated reflexion instance has no instance bound to it. If an instance is given in case the field is static, the instance will be ignored silently.
- Type Parameters:
T- the type of the data returned from the field.- Parameters:
instance- the instance to use when getting the field value.- Returns:
- the result of the get operation, either holding the field value or a read exception.
-
setValue
Sets the value of the wrapped field using the instance the reflexion object which created this instance is bound to (but only if the field is not static). This method never throws an exception, all exceptions are given back to the caller in the returned result instance.- Parameters:
value- the new value of the field.- Returns:
- the result of the set operation, either successful or holding the set exception.
-
setValue
@NotNull @NotNull Result<Void> setValue(@Nullable @Nullable Object instance, @Nullable @Nullable Object value) Sets the value of the wrapped field in the given object instance. This method never throws an exception, all exceptions are given back to the caller in the returned result instance.The given instance should be present in case the field is not static, and the associated reflexion instance has no instance bound to it. If an instance is given in case the field is static, the instance will be ignored silently.
- Parameters:
instance- the instance of the object to set the new field value in.value- the new value of the field to set.- Returns:
- the result of the set operation, either successful or holding the set exception.
-