W3cubDocs

/Groovy 3.0

[Java] Class ClassInfo

  • org.codehaus.groovy.reflection.ClassInfo
All Implemented Interfaces and Traits:
Finalizable
public class ClassInfo
extends Object
implements Finalizable

Handle for all information we want to keep about the class

This class handles caching internally and its advisable to not store references directly to objects of this class. The static factory method ClassInfo.getClassInfo 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

Nested classes
Modifiers Name Description
interface ClassInfo.ClassInfoAction

Field Summary

Fields
Modifiers Name Description
int hash

Methods Summary

Methods
Type Params Return Type Name and description
public static void clearModifiedExpandos()
public ClassInfo computeValue(Class<?> type)
public void finalizeReference()
public static int fullSize()
public static Collection<ClassInfo> getAllClassInfo()
public ClassLoaderForClassArtifacts getArtifactClassLoader()
public CachedClass getCachedClass()
public static ClassInfo getClassInfo(Class cls)
public final MetaClass getMetaClass()
Returns the MetaClass for the Class associated with this ClassInfo.
public MetaClass getMetaClass(Object obj)
public MetaClass getMetaClassForClass()
public ExpandoMetaClass getModifiedExpando()
public MetaClass getPerInstanceMetaClass(Object obj)
public MetaClass getStrongMetaClass()
public final Class<?> getTheClass()
Returns the Class associated with this ClassInfo.
public int getVersion()
public MetaClass getWeakMetaClass()
public boolean hasPerInstanceMetaClasses()
public void incVersion()
public void lock()
public static void onAllClassInfo(ClassInfo.ClassInfoAction action)
public static void remove(Class<?> cls)
Removes a ClassInfo from the cache.
public void setPerInstanceMetaClass(Object obj, MetaClass metaClass)
public void setStrongMetaClass(MetaClass answer)
public void setWeakMetaClass(MetaClass answer)
public static int size()
public void unlock()

Inherited Methods Summary

Inherited Methods
Methods inherited from class Name
class Object wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Field Detail

public final int hash

Method Detail

public static void clearModifiedExpandos()

@Override public ClassInfo computeValue(Class<?> type)

@Override public void finalizeReference()

public static int fullSize()

public static Collection<ClassInfo> getAllClassInfo()

public ClassLoaderForClassArtifacts getArtifactClassLoader()

public CachedClass getCachedClass()

public static ClassInfo getClassInfo(Class cls)

public final MetaClass getMetaClass()

Returns the 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 ClassInfo.getClassInfo to ensure the referenced Class is strongly reachable.

Returns:
a MetaClass instance

public MetaClass getMetaClass(Object obj)

public MetaClass getMetaClassForClass()

public ExpandoMetaClass getModifiedExpando()

public MetaClass getPerInstanceMetaClass(Object obj)

public MetaClass getStrongMetaClass()

public final Class<?> getTheClass()

Returns the 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.

Returns:
the Class associated with this ClassInfo, else null

public int getVersion()

public MetaClass getWeakMetaClass()

public boolean hasPerInstanceMetaClasses()

public void incVersion()

public void lock()

public static void onAllClassInfo(ClassInfo.ClassInfoAction action)

public static void remove(Class<?> cls)

Removes a 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.

Parameters:
cls - the Class associated with the ClassInfo to remove from cache

public void setPerInstanceMetaClass(Object obj, MetaClass metaClass)

public void setStrongMetaClass(MetaClass answer)

public void setWeakMetaClass(MetaClass answer)

public static int size()

public void unlock()

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/3.0.7/html/gapi/org/codehaus/groovy/reflection/ClassInfo.html