public class ClassInfo extends java.lang.Object implements Finalizable
This class handles caching internally and its 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.
Modifier and Type | Class and Description |
---|---|
static interface |
ClassInfo.ClassInfoAction |
Modifier and Type | Field and Description |
---|---|
int |
hash |
public final int hash
public int getVersion()
public void incVersion()
public ExpandoMetaClass getModifiedExpando()
public static void clearModifiedExpandos()
public final java.lang.Class<?> getTheClass()
Class
associated with this ClassInfo
.
This method can return null
if the Class
is no longer reachable
through any strong or soft references. A non-null return value indicates that this
ClassInfo
is valid.
Class
associated with this ClassInfo
, else null
public CachedClass getCachedClass()
public ClassLoaderForClassArtifacts getArtifactClassLoader()
public static ClassInfo getClassInfo(java.lang.Class cls)
public static void remove(java.lang.Class<?> cls)
ClassInfo
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 the ClassInfo
associated with the Class
will make the Class and its ClassLoader eligible for garbage collection sooner that
it would otherwise.cls
- the Class associated with the ClassInfo to remove
from cachepublic static java.util.Collection<ClassInfo> getAllClassInfo()
public static void onAllClassInfo(ClassInfo.ClassInfoAction action)
public MetaClass getStrongMetaClass()
public void setStrongMetaClass(MetaClass answer)
public MetaClass getWeakMetaClass()
public void setWeakMetaClass(MetaClass answer)
public MetaClass getMetaClassForClass()
public final MetaClass getMetaClass()
MetaClass
for the Class
associated with this ClassInfo
.
If no MetaClass
exists one will be created.
It is not safe to call this method without a Class
associated with this ClassInfo
.
It is advisable to aways retrieve a ClassInfo instance from the cache by using the static
factory method getClassInfo(Class)
to ensure the referenced Class is
strongly reachable.
MetaClass
instancepublic MetaClass getMetaClass(java.lang.Object obj)
public static int size()
public static int fullSize()
public void lock()
public void unlock()
public MetaClass getPerInstanceMetaClass(java.lang.Object obj)
public void setPerInstanceMetaClass(java.lang.Object obj, MetaClass metaClass)
public boolean hasPerInstanceMetaClasses()
public void finalizeReference()
finalizeReference
in interface Finalizable