public class ClassLocal<E>
extends java.lang.Object
ThreadLocal
class,
but stores one object per class instead of one object per thread.
The main usage for this class is to allow a superclass to hold one object for each subclass that is extending it.
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Class,E> |
objects |
Constructor and Description |
---|
ClassLocal()
Create a new
ClassLocal object. |
Modifier and Type | Method and Description |
---|---|
E |
get(java.lang.Object instance)
Get the object associated with the class of
the specified instance.
|
protected E |
initialValue(java.lang.Object instance)
Subclasses may override this to initialize the object
stored for that class.
|
void |
set(java.lang.Object instance,
E object)
Store an object and associate it with the class
of the specified instance.
|
private java.util.Map<java.lang.Class,E> objects
public E get(java.lang.Object instance)
instance
- An object instance of the classThreadLocal.get()
public void set(java.lang.Object instance, E object)
instance
- An object instance of the classobject
- The object to storeThreadLocal.set(Object)
protected E initialValue(java.lang.Object instance)
instance
- An object instance of the class