Invocable
interfacein packageklyn.reflection
public interface Invocable<ReturnType>:
Invocable

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
Properties
Modifier and Type Member Description
public readonly property name
name as String
Name of the executable entity.
public readonly property parameterCount
parameterCount as Int
Number of parameters expected.
public readonly property returnType
returnType as String
Return type.
Methods
Modifier and Type Member Description
public invoke
invoke(args as Object[]) as ReturnType throws Exception
Invokes the entity with dynamic arguments.
Operators
Modifier and Type Member Description
public operator call(args as Object[]) as ReturnType throws Exception Direct call operator.