Class VirtualField<T,F>
java.lang.Object
io.opentelemetry.instrumentation.api.util.VirtualField<T,F>
- Type Parameters:
T
- The type that will contain the new virtual field.F
- The field type that'll be added toT
.
Represents a "virtual" field of type
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> abstract F
Gets the value of this virtual field.abstract void
Sets the new value of this virtual field.
-
Constructor Details
-
VirtualField
public VirtualField()
-
-
Method Details
-
find
public static <U extends T,V extends F, VirtualField<U,T, F> V> find(Class<T> type, Class<F> fieldType) Finds aVirtualField
instance for giventype
andfieldType
.Conceptually this can be thought of as a map lookup to fetch a second level map given
type
.In runtime, when using the javaagent, the calls to this method are rewritten to something more performant while injecting advice into a method.
When using this method outside of Advice method, the
VirtualField
should be looked up once and stored in a field to avoid repeatedly calling this method.- Parameters:
type
- The type that will contain the new virtual field.fieldType
- The field type that will be added totype
.
-
get
Gets the value of this virtual field. -
set
Sets the new value of this virtual field.
-