public class CachedMethod
extends MetaMethod
implements Comparable
Caches reflection information about a single method for fast lookup and invocation.
Extends MetaMethod and implements Comparable for method sorting. Provides efficient access to method metadata and supports call site optimization.
| Modifiers | Name | Description |
|---|---|---|
static CachedMethod[] |
EMPTY_ARRAY |
An empty array constant representing zero cached methods. |
CachedClass |
cachedClass |
The cached class that declares this method. |
| Fields inherited from class | Fields |
|---|---|
class MetaMethod |
EMPTY_ARRAY |
| Constructor and description |
|---|
CachedMethod(CachedClass clazz, Method method)Constructs a CachedMethod for the given method within a cached class. |
CachedMethod(Method method)Constructs a CachedMethod for the given Java method.
|
| Type Params | Return Type | Name and description |
|---|---|---|
|
public boolean |
canAccessLegally(Class<?> callerClass)Checks whether the given caller class can legally access this method. |
|
public int |
compareTo(Object other)Compares this cached method with another method-like object for ordering. |
|
public CallSite |
createPogoMetaMethodSite(CallSite site, MetaClassImpl metaClass, Class[] params)Creates an optimized call site for invoking this method on POGO (Groovy) objects. |
|
public CallSite |
createPojoMetaMethodSite(CallSite site, MetaClassImpl metaClass, Class[] params)Creates an optimized call site for invoking this method on POJO (plain Java) objects. |
|
public CallSite |
createStaticMetaMethodSite(CallSite site, MetaClassImpl metaClass, Class[] params)Creates an optimized call site for invoking this static method. |
|
public boolean |
equals(Object other)Checks equality with another method. |
|
public static CachedMethod |
find(Method method)Finds a CachedMethod corresponding to the specified Java method
by searching the cached methods of its declaring class. |
<T extends Annotation> |
public T |
getAnnotation(Class<T> annotationClass)Returns the annotation of the specified type on this method, if present. |
|
public Method |
getCachedMethod()Returns the underlying Java method, making it accessible if necessary. |
|
public CachedClass |
getDeclaringClass()Returns the cached class that declares this method. |
|
public String |
getDescriptor()Returns the bytecode method descriptor for this method (e.g., "(II)Z"). |
|
public int |
getModifiers()Returns the modifiers of this method (e.g., public, static, synchronized). |
|
public String |
getName()Returns the name of this method. |
|
public Class[] |
getPT()Returns the native Java parameter types of this method. |
|
public ParameterTypes |
getParamTypes()Returns the parameter type information for this method. |
|
public int |
getParamsCount()Returns the number of parameters this method accepts. |
|
public Class |
getReturnType()Returns the return type of this method. |
|
public String |
getSignature()Returns the complete method signature (name + bytecode descriptor). |
|
public CachedMethod |
getTransformedMethod()Returns the transformed version of this method, if one exists. |
|
public int |
hashCode()Returns the hash code for this cached method based on the underlying Java method. |
|
public final Object |
invoke(Object object, Object[] arguments)Invokes this method on the given object with the specified arguments. |
|
public boolean |
isSynthetic()Returns whether this method is synthetic (generated by the compiler). |
|
public final Method |
setAccessible()Makes this method accessible and returns the underlying Java method. |
|
public void |
setTransformedMethod(CachedMethod transformedMethod)Sets the transformed version of this method. |
|
public String |
toString()Returns the string representation of the underlying Java method. |
| Methods inherited from class | Name |
|---|---|
class MetaMethod |
checkParameters, clone, doMethodInvoke, equal, equal, getDeclaringClass, getDescriptor, getModifiers, getMopName, getName, getReturnType, getSignature, invoke, isAbstract, isCacheable, isDefault, isMethod, isSame, processDoMethodInvokeException, toString |
class ParameterTypes |
coerceArgumentsToClasses, correctArguments, getNativeParameterTypes, getPT, getParameterTypes, isValidExactMethod, isValidExactMethod, isValidMethod, isValidMethod, isVargsMethod, isVargsMethod, setParametersTypes |
An empty array constant representing zero cached methods.
The cached class that declares this method.
Constructs a CachedMethod for the given method within a cached class.
clazz - the cached class that declares this methodmethod - the Java method to cache Constructs a CachedMethod for the given Java method.
Automatically resolves the cached class from the method's declaring class.
method - the Java method to cacheChecks whether the given caller class can legally access this method.
callerClass - the class attempting to access this methodtrue if access is allowed; false otherwiseCompares this cached method with another method-like object for ordering. Comparison is based on method name, return type, parameters, and declaring class.
other - the object to compare with (typically another CachedMethod or Method)Creates an optimized call site for invoking this method on POGO (Groovy) objects. Attempts to compile the method for maximum performance.
site - the call site being createdmetaClass - the metaclass of the target object's classparams - the parameter types of the callCreates an optimized call site for invoking this method on POJO (plain Java) objects. Attempts to compile the method for maximum performance.
site - the call site being createdmetaClass - the metaclass of the target object's classparams - the parameter types of the callCreates an optimized call site for invoking this static method. Attempts to compile the method for maximum performance.
site - the call site being createdmetaClass - the metaclass associated with the static methodparams - the parameter types of the callChecks equality with another method. Two methods are equal if they represent the same underlying Java method.
other - the object to compare withtrue if this method equals the other object; false otherwise Finds a CachedMethod corresponding to the specified Java method
by searching the cached methods of its declaring class.
method - the method to findnull if not foundReturns the annotation of the specified type on this method, if present.
T - the annotation typeannotationClass - the class of the annotation to retrievenull if not presentReturns the underlying Java method, making it accessible if necessary.
Returns the cached class that declares this method.
Returns the bytecode method descriptor for this method (e.g., "(II)Z"). The descriptor encodes parameter and return types in JVM format.
Returns the modifiers of this method (e.g., public, static, synchronized). See Modifier for modifier constants.
Returns the name of this method.
Returns the native Java parameter types of this method.
Returns the parameter type information for this method.
Note: This method always returns null and is retained for compatibility.
nullReturns the number of parameters this method accepts.
Returns the return type of this method.
Returns the complete method signature (name + bytecode descriptor). For example: "toString()Ljava/lang/String;"
Returns the transformed version of this method, if one exists. Transformed methods are compiler-optimized variants.
null if no transformation existsReturns the hash code for this cached method based on the underlying Java method.
Invokes this method on the given object with the specified arguments. Handles accessibility, exception wrapping, and method invocation.
object - the target object (may be null for static methods)arguments - the arguments to pass to the methodReturns whether this method is synthetic (generated by the compiler).
true if this method is synthetic; false otherwiseMakes this method accessible and returns the underlying Java method. Synonym for getCachedMethod().
Sets the transformed version of this method.
transformedMethod - the transformed method, or null to clearReturns the string representation of the underlying Java method.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.