public interface Invocable<ReturnType>:
Common reflective interface for executable entities whose parameter signature is discovered at runtime.
Invocable deliberately receives an Object[]: it is intended for reflection, evaluated code, methods, and constructors. When parameter types are known at compile time, use a structural function type such as (Int, Int) -> Int instead. That form preserves arity and parameter types for static checking. Klyn does not implicitly erase a structural function into an Invocable; reflective values must originate from a reflective API.
import klyn.reflection
# Function discovered through eval
f = eval("def fct(a as Int): return a * 2")
if f is Invocable<Int>:
invokeArgs as Object[] = f:[21]
result = f.invoke(invokeArgs)
# Constructor via reflection
constructor as Invocable<Object> = User.type.getConstructor()
constructorArgs as Object[] = f:["Alice"]
user = constructor.invoke(constructorArgs) as User| Modifier and Type | Member | Description |
|---|---|---|
| public readonly property | namename as String |
Name of the executable entity. |
| public readonly property | parameterCountparameterCount as Int |
Number of parameters expected. |
| public readonly property | returnTypereturnType as String |
Return type. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | invoke | Invokes the entity with dynamic arguments. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | operator call(args as Object[]) as ReturnType throws Exception | Direct call operator. |