org.dynalang.classtoken
public class ClassToken extends java.lang.Object
Class
object in various contexts where it is undesirable
to keep a strong reference to the Class object itself. This class guarantees
that at most one ClassToken object exists for every loaded Class object.
Holding a reference to a ClassToken does not prevent the Class object from
unloading. There is an event listener mechanism to observe when a ClassToken
becomes invalid (its associated class becomes unloaded).Constructor and Description |
---|
ClassToken() |
Modifier and Type | Method and Description |
---|---|
static void |
addClassRefListener(ClassTokenListener listener)
Adds a
ClassTokenListener that will get notified whenever a
ClassToken object gets invalidated. |
static ClassToken |
forClass(java.lang.Class<?> clazz)
Gets a class token for a given class.
|
static void |
removeClassRefListener(ClassTokenListener listener)
Removes a
ClassTokenListener previously registered with the
addClassRefListener(ClassTokenListener) method. |
public static ClassToken forClass(java.lang.Class<?> clazz)
clazz
- the class for which the token is requestedpublic static void addClassRefListener(ClassTokenListener listener)
ClassTokenListener
that will get notified whenever a
ClassToken
object gets invalidated.listener
- the listenerpublic static void removeClassRefListener(ClassTokenListener listener)
ClassTokenListener
previously registered with the
addClassRefListener(ClassTokenListener)
method. It is not
strictly necessary to eagerly remove listeners, as this class references
its listeners weakly, and won't prevent a listener from getting garbage
collected.listener
- the listener