Class OpenMethod
java.lang.Object
cloud.opencode.base.reflect.OpenMethod
Method Facade Entry Class
方法门面入口类
Provides common method operations API, internally delegates to MethodUtil. Similar to Commons Lang MethodUtils.
提供常用方法操作API,内部委托给MethodUtil。 对标Commons Lang MethodUtils。
Features | 主要功能:
- Method retrieval (with inheritance) - 方法获取(含继承)
- Method invocation - 方法调用
- Getter/Setter detection - Getter/Setter检测
- Annotation-based filtering - 基于注解的过滤
Usage Examples | 使用示例:
// Invoke a method
Object result = OpenMethod.invokeMethod(target, "getName");
// Get all methods with annotation
List<Method> methods = OpenMethod.getMethodsWithAnnotation(MyClass.class, Override.class);
// Check if method is getter
boolean isGetter = OpenMethod.isGetter(method);
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: No (caller must ensure non-null arguments) - 空值安全: 否(调用方须确保非空参数)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionFinds first matching method 查找第一个匹配方法static voidIterates all methods 遍历所有方法getAllMethods(Class<?> clazz) Gets all methods (including inherited) 获取所有方法(包含继承)getDeclaredMethods(Class<?> clazz) Gets declared methods (not inherited) 获取声明方法(不含继承)getGetters(Class<?> clazz) Gets all getter methods 获取所有Getter方法static MethodgetMatchingMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) Gets a matching method (compatible parameter types) 获取匹配方法(兼容参数类型)static MethodGets a method with optional force access 获取方法(可选强制访问)static MethodGets a method (exact parameter types) 获取方法(精确参数类型匹配)getMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass) Gets methods with specific annotation 按注解获取方法getOverloadMethods(Class<?> clazz, String methodName) Gets overloaded methods by name 按名称获取所有重载方法getSetters(Class<?> clazz) Gets all setter methods 获取所有Setter方法static booleanChecks if a method exists 检查方法是否存在static ObjectinvokeMethod(Object target, boolean forceAccess, String methodName, Object... args) Invokes a method with optional force access 调用方法(可选强制访问)static <T> TinvokeMethod(Object target, String methodName, Class<T> returnType, Object... args) Invokes a method with type-safe return 调用方法(泛型安全)static ObjectinvokeMethod(Object target, String methodName, Object... args) Invokes a method 调用方法static <T> TinvokeStaticMethod(Class<?> clazz, String methodName, Class<T> returnType, Object... args) Invokes a static method with type-safe return 调用静态方法(泛型安全)static ObjectinvokeStaticMethod(Class<?> clazz, String methodName, Object... args) Invokes a static method 调用静态方法static booleanChecks if a method is a getter 检查是否为Getter方法static booleanChecks if a method is a setter 检查是否为Setter方法Creates a method stream 创建方法流toInvokable(Method method) Converts to Invokable 转为Invokable
-
Method Details
-
getMethod
Gets a method (exact parameter types) 获取方法(精确参数类型匹配)- Parameters:
clazz- the class | 类methodName- the method name | 方法名parameterTypes- the parameter types | 参数类型- Returns:
- the method | 方法
- Throws:
OpenReflectException- if not found | 如果未找到
-
getMethod
public static Method getMethod(Class<?> clazz, String methodName, boolean forceAccess, Class<?>... parameterTypes) Gets a method with optional force access 获取方法(可选强制访问)- Parameters:
clazz- the class | 类methodName- the method name | 方法名forceAccess- whether to force access | 是否强制访问parameterTypes- the parameter types | 参数类型- Returns:
- the method | 方法
- Throws:
OpenReflectException- if not found | 如果未找到
-
getMatchingMethod
public static Method getMatchingMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) Gets a matching method (compatible parameter types) 获取匹配方法(兼容参数类型)- Parameters:
clazz- the class | 类methodName- the method name | 方法名parameterTypes- the parameter types | 参数类型- Returns:
- the method | 方法
- Throws:
OpenReflectException- if not found | 如果未找到
-
getAllMethods
-
getDeclaredMethods
-
getMethodsWithAnnotation
public static List<Method> getMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass) Gets methods with specific annotation 按注解获取方法- Parameters:
clazz- the class | 类annotationClass- the annotation class | 注解类- Returns:
- list of methods | 方法列表
-
getOverloadMethods
-
getGetters
-
getSetters
-
invokeMethod
-
invokeMethod
public static Object invokeMethod(Object target, boolean forceAccess, String methodName, Object... args) Invokes a method with optional force access 调用方法(可选强制访问)- Parameters:
target- the target object | 目标对象forceAccess- whether to force access | 是否强制访问methodName- the method name | 方法名args- the arguments | 参数- Returns:
- the result | 结果
-
invokeMethod
public static <T> T invokeMethod(Object target, String methodName, Class<T> returnType, Object... args) Invokes a method with type-safe return 调用方法(泛型安全)- Type Parameters:
T- the return type | 返回类型- Parameters:
target- the target object | 目标对象methodName- the method name | 方法名returnType- the return type | 返回类型args- the arguments | 参数- Returns:
- the result | 结果
-
invokeStaticMethod
-
invokeStaticMethod
public static <T> T invokeStaticMethod(Class<?> clazz, String methodName, Class<T> returnType, Object... args) Invokes a static method with type-safe return 调用静态方法(泛型安全)- Type Parameters:
T- the return type | 返回类型- Parameters:
clazz- the class | 类methodName- the method name | 方法名returnType- the return type | 返回类型args- the arguments | 参数- Returns:
- the result | 结果
-
hasMethod
-
isGetter
Checks if a method is a getter 检查是否为Getter方法- Parameters:
method- the method | 方法- Returns:
- true if getter | 如果是Getter返回true
-
isSetter
Checks if a method is a setter 检查是否为Setter方法- Parameters:
method- the method | 方法- Returns:
- true if setter | 如果是Setter返回true
-
forEach
-
findFirst
-
stream
-
toInvokable
-