Class ClassInfo
- All Implemented Interfaces:
Finalizable
This class handles caching internally and it's advisable to not store
references directly to objects of this class. The static factory method
getClassInfo(Class)
should be used to retrieve an instance
from the cache. Internally the Class
associated with a ClassInfo
instance is kept as WeakReference
, so it not safe to reference
and instance without the Class being either strongly or softly reachable.
-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
void
static int
fullSize()
static Collection<ClassInfo>
static ClassInfo
getClassInfo
(Class cls) final MetaClass
Returns theMetaClass
for theClass
associated with thisClassInfo
.getMetaClass
(Object obj) final Class<?>
Returns theClass
associated with thisClassInfo
.int
boolean
void
void
lock()
static void
static void
Removes aClassInfo
from the cache.void
setPerInstanceMetaClass
(Object obj, MetaClass metaClass) void
setStrongMetaClass
(MetaClass answer) void
setWeakMetaClass
(MetaClass answer) static int
size()
void
unlock()
-
Field Details
-
hash
public final int hash- See Also:
-
-
Method Details
-
getVersion
public int getVersion() -
incVersion
public void incVersion() -
getModifiedExpando
-
clearModifiedExpandos
public static void clearModifiedExpandos() -
getTheClass
Returns theClass
associated with thisClassInfo
.This method can return
null
if theClass
is no longer reachable through any strong or soft references. A non-null return value indicates that thisClassInfo
is valid.- Returns:
- the
Class
associated with thisClassInfo
, elsenull
-
getCachedClass
-
getArtifactClassLoader
-
getClassInfo
-
remove
Removes aClassInfo
from the cache. This is useful in cases where the Class is parsed from a script, such as when using GroovyClassLoader#parseClass, and is executed for its result but the Class is not retained or cached. Removing theClassInfo
associated with the Class will make the Class and its ClassLoader eligible for garbage collection sooner that it would otherwise.- Parameters:
cls
- the Class associated with the ClassInfo to remove from cache
-
getAllClassInfo
-
onAllClassInfo
-
getStrongMetaClass
-
setStrongMetaClass
-
getWeakMetaClass
-
setWeakMetaClass
-
getMetaClassForClass
-
getMetaClass
Returns theMetaClass
for theClass
associated with thisClassInfo
. If noMetaClass
exists one will be created.It is not safe to call this method without a
Class
associated with thisClassInfo
. It is advisable to always retrieve a ClassInfo instance from the cache by using the static factory methodgetClassInfo(Class)
to ensure the referenced Class is strongly reachable.- Returns:
- a
MetaClass
instance
-
getMetaClass
-
size
public static int size() -
fullSize
public static int fullSize() -
lock
public void lock() -
unlock
public void unlock() -
getPerInstanceMetaClass
-
setPerInstanceMetaClass
-
hasPerInstanceMetaClasses
public boolean hasPerInstanceMetaClasses() -
finalizeReference
public void finalizeReference()- Specified by:
finalizeReference
in interfaceFinalizable
-