descendants
.
ClassLoaderValue allows associating a
computed
non-null value with
a (ClassLoader, keys...)
tuple. The associated value, as well as the
keys are strongly reachable from the associated ClassLoader so care should be
taken to use such keys and values that only reference types resolvable from
the associated ClassLoader. Failing that, ClassLoader leaks are inevitable.
Example usage:
// create a root instance which represents a namespace and declares the type of
// associated values (Class instances in this example)
static final ClassLoaderValue<Class<?>> proxyClasses = new ClassLoaderValue<>();
// create a compound key composed of a Module and a list of interfaces
Module module = ...;
List<Class<?>> interfaces = ...;
ClassLoaderValue<Class<?>>.Sub<Module>.Sub<List<Class<?>>> key =
proxyClasses.sub(module).sub(interfaces);
// use the compound key together with ClassLoader to lazily associate
// the value with tuple (loader, module, interfaces) and return it
ClassLoader loader = ...;
Class<?> proxyClass = key.computeIfAbsent(loader, (ld, ky) -> {
List<Class<?>> intfcs = ky.key();
Module m = ky.parent().key();
Class<?> clazz = defineProxyClass(ld, m, intfcs);
return clazz;
});
classLoaderValue.<operation>(classLoader, ...)
represents an operation
to get
, putIfAbsent
, computeIfAbsent
or remove
a value associated with a (classLoader, classLoaderValue) tuple. ClassLoader
instances and root-ClassLoaderValue
instances are compared using
identity equality while sub
-ClassLoaderValue instances define
equality
in terms of equality of its
parent
ClassLoaderValue and its
key
component.
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public boolean | isEqualOrDescendantOf(AbstractClassLoaderValue<?, V>
the ClassLoaderValue to test this against clv)Implements abstract jdk. root-ClassLoaderValue can only be equal to itself and has no predecessors. |
public ClassLoaderValue | Returns: the key component of this root-ClassLoaderValue (itself).Implements abstract jdk. Returns the key component of this ClassLoaderValue. |
ClassLoaderValue | back to summary |
---|---|
public ClassLoaderValue() Constructs new root-ClassLoaderValue representing its own namespace. |
isEqualOrDescendantOf | back to summary |
---|---|
public boolean isEqualOrDescendantOf(AbstractClassLoaderValue<?, V> clv) Implements abstract jdk. root-ClassLoaderValue can only be equal to itself and has no predecessors.
|
key | back to summary |
---|---|
public ClassLoaderValue Implements abstract jdk. Doc from jdk. Returns the key component of this ClassLoaderValue. The key component of
the root-
|