Class VirtualField<T,F>
- Type Parameters:
T- The type that will contain the new virtual field.F- The field type that'll be added toT.
F that is added to type T in the runtime.
A virtual field has similar semantics to a weak-keys strong-values map: the value will be garbage collected when their owner instance is collected. It is discouraged to use a virtual field for keeping values that might reference their key, as it may cause memory leaks.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <U extends T, V extends F, T, F>
VirtualField<U, V> static <U extends T, V extends F, T, F>
VirtualField<U, V> abstract FGets the value of this virtual field.abstract voidSets the new value of this virtual field.
-
Constructor Details
-
VirtualField
public VirtualField()
-
-
Method Details
-
find
public static <U extends T, V extends F, T, F> VirtualField<U,V> find(Class<T> type, Class<F> fieldType) Finds aVirtualFieldinstance for giventypeandfieldType.In runtime, when using the javaagent, the calls to this method are rewritten to something more performant while injecting inline advice into a method. This rewriting is not performed for non-inline advice. Users are advised not to rely on agent automatically rewriting the virtual field usages and instead look up
VirtualFieldonce and stored in a field to avoid repeatedly calling this method. Rewriting calls to this method may be removed in a future agent release.- Parameters:
type- The type that will contain the new virtual field.fieldType- The field type that will be added totype.- See Also:
-
find
public static <U extends T, V extends F, T, F> VirtualField<U,V> find(Class<T> type, Class<F> fieldType, String fieldName) Finds aVirtualFieldinstance for giventype,fieldTypeandfieldName.Conceptually this can be thought of as adding a field with name
fieldNameto classtypewith typefieldType. Alternatively this can be viewed as a map where an object of typetypeis associated with another map where they key is composed offieldNameandfieldTypeand the value is the value of the virtual field.Calls to this method may be expensive, caller should keep the returned
VirtualFieldand reuse it instead of repeatedly calling this method.Unlike calls to
find(Class, Class)calls to this method are never rewritten.- Parameters:
type- The type that will contain the new virtual field.fieldType- The field type that will be added totype.fieldName- The name of the virtual field.
-
get
-
set
-