Class MethodUtil
java.lang.Object
cloud.opencode.base.core.reflect.MethodUtil
Method Utility Class - Method reflection operations
方法工具类 - 方法反射操作
Provides utilities for method discovery, getter/setter detection, and invocation.
提供方法发现、Getter/Setter 检测和调用操作工具。
Features | 主要功能:
- Get all/declared methods (with inheritance) - 获取全部/声明方法(含继承)
- Getter/Setter detection and property extraction - Getter/Setter 检测和属性提取
- Filter by annotation, return type, modifier - 按注解、返回类型、修饰符过滤
- Method invocation (instance/static) - 方法调用(实例/静态)
Usage Examples | 使用示例:
// Get getter methods - 获取 Getter 方法
List<Method> getters = MethodUtil.getGetterMethods(User.class);
// Check if getter - 检查是否为 Getter
boolean isGetter = MethodUtil.isGetter(method);
// Get property name - 获取属性名
String prop = MethodUtil.getPropertyNameFromGetter(method);
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: No - 空值安全: 否
Performance | 性能特性:
- Time complexity: O(n) where n = declared methods - O(n), n为声明的方法数
- Space complexity: O(1) per invocation - 每次调用 O(1)
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongetAllMethods(Class<?> clazz) Gets all methods (including superclass) 获取所有方法(包括父类)getDeclaredMethods(Class<?> clazz) Gets declared methods (excluding superclass) 获取声明的方法(不包括父类)static Type[]getGenericParameterTypes(Method method) Gets the generic parameter types of a method 获取方法的泛型参数类型static TypegetGenericReturnType(Method method) Gets the generic return type of a method 获取方法的泛型返回类型getGetterMethods(Class<?> clazz) Gets getter methods 获取 Getter 方法Gets a method (exact parameter type match) 获取方法(精确匹配参数类型)getMethodsByName(Class<?> clazz, String name) Gets methods by name 按名称获取方法getMethodsByReturnType(Class<?> clazz, Class<?> returnType) Gets methods with the specified return type 获取指定返回类型的方法getMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) Gets methods with the specified annotation 获取带有指定注解的方法static StringgetPropertyNameFromGetter(Method method) Gets the property name from a getter method name 从 Getter 方法名获取属性名static StringgetPropertyNameFromSetter(Method method) Gets the property name from a setter method name 从 Setter 方法名获取属性名getPublicMethods(Class<?> clazz) Gets public methods 获取公共方法getSetterMethods(Class<?> clazz) Gets setter methods 获取 Setter 方法getStaticMethods(Class<?> clazz) Gets static methods 获取静态方法static <T> TInvokes a method 调用方法static <T> TinvokeStatic(Method method, Object... args) Invokes a static method 调用静态方法static booleanisAbstract(Method method) Checks if the method is abstract 检查方法是否为 abstractstatic booleanChecks if the method is a default interface method 检查方法是否为 default 接口方法static booleanChecks if the method is a getter 检查是否为 Getter 方法static booleanChecks if the method is native 检查方法是否为 nativestatic booleanChecks if the method is a setter 检查是否为 Setter 方法static booleanisSynchronized(Method method) Checks if the method is synchronized 检查方法是否为 synchronized
-
Method Details
-
getAllMethods
-
getDeclaredMethods
-
getMethodsByName
-
getMethod
-
getMethodsWithAnnotation
public static List<Method> getMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) Gets methods with the specified annotation 获取带有指定注解的方法 -
getMethodsByReturnType
-
getGetterMethods
-
getSetterMethods
-
getStaticMethods
-
getPublicMethods
-
isGetter
Checks if the method is a getter 检查是否为 Getter 方法 -
isSetter
Checks if the method is a setter 检查是否为 Setter 方法 -
getPropertyNameFromGetter
-
getPropertyNameFromSetter
-
getGenericReturnType
-
getGenericParameterTypes
-
invoke
-
invokeStatic
-
isAbstract
Checks if the method is abstract 检查方法是否为 abstract -
isSynchronized
Checks if the method is synchronized 检查方法是否为 synchronized -
isNative
Checks if the method is native 检查方法是否为 native -
isDefault
Checks if the method is a default interface method 检查方法是否为 default 接口方法
-