Package org.codehaus.groovy.reflection
Interface GroovyClassValue<T>
- Type Parameters:
T- the value stored for each class
- All Known Implementing Classes:
GroovyClassValueJava7
public interface GroovyClassValue<T>
Abstraction for Java version dependent ClassValue implementations.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceComputes the value stored for a class that has none yet. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value associated withtype, computing it when absent.default voidKeepsvaluestrongly reachable from its own key's association untilunpin(java.lang.Class<?>, T)orremove(java.lang.Class<?>).voidDrops the association fortype, including a pinned value.default voidRevertspin(java.lang.Class<?>, T): the association holdsvaluereclaimably again.default booleanWhether an association's value can be collected while its key class is still alive (GROOVY-12281,-Dgroovy.use.classvalue=soft).
-
Method Details
-
get
Returns the value associated withtype, computing it when absent.- Parameters:
type- the key class- Returns:
- the associated value
-
remove
Drops the association fortype, including a pinned value.- Parameters:
type- the key class
-
valuesReclaimable
default boolean valuesReclaimable()Whether an association's value can be collected while its key class is still alive (GROOVY-12281,-Dgroovy.use.classvalue=soft). The default — a value lives exactly as long as its key class — answersfalse. Implementations answeringtruemust honorpin(java.lang.Class<?>, T)so callers can exempt values whose state cannot be rebuilt by recomputation.- Returns:
trueif values may be collected before their key class
-
pin
Keepsvaluestrongly reachable from its own key's association untilunpin(java.lang.Class<?>, T)orremove(java.lang.Class<?>). The value then lives exactly as long astype— like a plainjava.lang.ClassValueassociation: an immortal key retains it, a collectible key releases it together with its loader. Implementations must not root the value globally, which would extend a collectible key's lifetime to the runtime's. No-op unlessvaluesReclaimable().- Parameters:
type- the key classvalue- the current value fortype
-
unpin
Revertspin(java.lang.Class<?>, T): the association holdsvaluereclaimably again. No-op whenvalueis not the currently pinned value, and unlessvaluesReclaimable().- Parameters:
type- the key classvalue- the value to release
-