Class Invokable<T,R>
java.lang.Object
cloud.opencode.base.reflect.invokable.Invokable<T,R>
- Type Parameters:
T- the declaring class type | 声明类类型R- the return type | 返回类型
- All Implemented Interfaces:
AnnotatedElement
- Direct Known Subclasses:
ConstructorInvokable, MethodInvokable
Invokable - Fluent Wrapper for Method/Constructor (Similar to Guava Invokable)
可调用 - 方法/构造器的流畅包装(对标 Guava Invokable)
Provides a unified, fluent API for invoking methods and constructors with type safety and rich metadata access.
为调用方法和构造器提供统一、流畅的API,具有类型安全和丰富的元数据访问。
Features | 主要功能:
- Unified method/constructor API - 统一的方法/构造器API
- Type-safe invocation - 类型安全调用
- Modifier inspection - 修饰符检查
- Annotation access - 注解访问
Usage Examples | 使用示例:
// From Method
Invokable<Service, String> invokable = Invokable.from(method);
String result = invokable.invoke(service, args);
// From Constructor
Invokable<User, User> ctor = Invokable.from(constructor);
User user = ctor.invoke(null, "name", 25);
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
- Null-safe: No (wrapped method/constructor must be non-null) - 空值安全: 否(包装的方法/构造器须非空)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Invokable<T, T> from(Constructor<T> constructor) Creates an Invokable from a Constructor 从Constructor创建InvokableCreates an Invokable from a Method 从Method创建Invokableprotected abstract AccessibleObjectGets the underlying accessible object 获取底层可访问对象<A extends Annotation>
AgetAnnotation(Class<A> annotationClass) <A extends Annotation>
A[]getAnnotationsByType(Class<A> annotationClass) <A extends Annotation>
AgetDeclaredAnnotation(Class<A> annotationClass) <A extends Annotation>
A[]getDeclaredAnnotationsByType(Class<A> annotationClass) Gets the declaring class as TypeToken 获取声明类的TypeTokenabstract Class<?> Gets the declaring class as raw Class 获取声明类的原始ClassGets the exception types 获取异常类型abstract intGets the modifiers 获取修饰符abstract StringgetName()Gets the name 获取名称Gets the parameter list 获取参数列表Gets the parameter types 获取参数类型Gets the return type as TypeToken 获取返回类型的TypeTokenabstract TypeVariable<?>[]Gets the type parameters 获取类型参数abstract RInvokes the method/constructor 调用方法/构造器invokeForced(T receiver, Object... args) Invokes ignoring access modifiers 调用(忽略访问修饰符)invokeSafe(T receiver, Object... args) Safely invokes returning Optional 安全调用返回OptionalbooleanChecks if abstract 检查是否为abstractbooleanisAnnotationPresent(Class<? extends Annotation> annotationClass) booleanisFinal()Checks if final 检查是否为finalbooleanisNative()Checks if native 检查是否为nativebooleanChecks if overridable (not final, not private, not static) 检查是否可重写(非final、非private、非static)booleanChecks if package-private 检查是否为包私有booleanChecks if private 检查是否为privatebooleanChecks if protected 检查是否为protectedbooleanisPublic()Checks if public 检查是否为publicbooleanisStatic()Checks if static 检查是否为staticbooleanChecks if synchronized 检查是否为synchronizedabstract booleanChecks if synthetic 检查是否为合成abstract booleanChecks if varargs 检查是否为可变参数setAccessible(boolean flag) Sets accessible flag 设置可访问标志
-
Constructor Details
-
Invokable
public Invokable()
-
-
Method Details
-
from
-
from
Creates an Invokable from a Constructor 从Constructor创建Invokable- Type Parameters:
T- the type | 类型- Parameters:
constructor- the constructor | 构造器- Returns:
- Invokable instance | Invokable实例
-
getAccessibleObject
Gets the underlying accessible object 获取底层可访问对象- Returns:
- the accessible object | 可访问对象
-
getDeclaringClass
-
getReturnType
-
getParameters
-
getParameterTypes
-
getExceptionTypes
-
getTypeParameters
Gets the type parameters 获取类型参数- Returns:
- array of type variables | 类型变量数组
-
invoke
public abstract R invoke(T receiver, Object... args) throws InvocationTargetException, IllegalAccessException Invokes the method/constructor 调用方法/构造器- Parameters:
receiver- the receiver object | 接收对象args- the arguments | 参数- Returns:
- the result | 结果
- Throws:
InvocationTargetException- if invocation fails | 如果调用失败IllegalAccessException- if access denied | 如果访问被拒绝
-
invokeForced
-
invokeSafe
-
setAccessible
-
isPublic
public boolean isPublic()Checks if public 检查是否为public- Returns:
- true if public | 如果是public返回true
-
isProtected
public boolean isProtected()Checks if protected 检查是否为protected- Returns:
- true if protected | 如果是protected返回true
-
isPrivate
public boolean isPrivate()Checks if private 检查是否为private- Returns:
- true if private | 如果是private返回true
-
isPackagePrivate
public boolean isPackagePrivate()Checks if package-private 检查是否为包私有- Returns:
- true if package-private | 如果是包私有返回true
-
isStatic
public boolean isStatic()Checks if static 检查是否为static- Returns:
- true if static | 如果是static返回true
-
isFinal
public boolean isFinal()Checks if final 检查是否为final- Returns:
- true if final | 如果是final返回true
-
isAbstract
public boolean isAbstract()Checks if abstract 检查是否为abstract- Returns:
- true if abstract | 如果是abstract返回true
-
isNative
public boolean isNative()Checks if native 检查是否为native- Returns:
- true if native | 如果是native返回true
-
isSynchronized
public boolean isSynchronized()Checks if synchronized 检查是否为synchronized- Returns:
- true if synchronized | 如果是synchronized返回true
-
isVarArgs
public abstract boolean isVarArgs()Checks if varargs 检查是否为可变参数- Returns:
- true if varargs | 如果是可变参数返回true
-
isSynthetic
public abstract boolean isSynthetic()Checks if synthetic 检查是否为合成- Returns:
- true if synthetic | 如果是合成返回true
-
getName
-
getModifiers
public abstract int getModifiers()Gets the modifiers 获取修饰符- Returns:
- the modifiers | 修饰符
-
getDeclaringClassRaw
Gets the declaring class as raw Class 获取声明类的原始Class- Returns:
- the declaring class | 声明类
-
isOverridable
public boolean isOverridable()Checks if overridable (not final, not private, not static) 检查是否可重写(非final、非private、非static)- Returns:
- true if overridable | 如果可重写返回true
-
isAnnotationPresent
- Specified by:
isAnnotationPresentin interfaceAnnotatedElement
-
getAnnotation
- Specified by:
getAnnotationin interfaceAnnotatedElement
-
getAnnotations
- Specified by:
getAnnotationsin interfaceAnnotatedElement
-
getAnnotationsByType
- Specified by:
getAnnotationsByTypein interfaceAnnotatedElement
-
getDeclaredAnnotation
- Specified by:
getDeclaredAnnotationin interfaceAnnotatedElement
-
getDeclaredAnnotationsByType
- Specified by:
getDeclaredAnnotationsByTypein interfaceAnnotatedElement
-
getDeclaredAnnotations
- Specified by:
getDeclaredAnnotationsin interfaceAnnotatedElement
-