Interface Function
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Function Interface
函数接口
Represents a callable function in expressions.
表示表达式中可调用的函数。
Features | 主要功能:
- Functional interface for lambda-based function definition - 函数式接口,支持lambda定义
- Variable argument support - 可变参数支持
- Argument count validation - 参数数量验证
Usage Examples | 使用示例:
// Register a custom function
Function myFunc = args -> ((Number) args[0]).intValue() * 2;
registry.register("double", myFunc);
// Use in expression
Object result = OpenExpression.eval("double(21)"); // 42
Security | 安全性:
- Thread-safe: Depends on implementation - 线程安全: 取决于实现
- Null-safe: Depends on implementation - 空值安全: 取决于实现
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionApply the function 应用函数default intGet maximum argument count 获取最大参数数量default intGet minimum argument count 获取最小参数数量default StringgetName()Get function name 获取函数名default booleanisValidArgCount(int argCount) Check if argument count is valid 检查参数数量是否有效
-
Method Details
-
apply
-
getName
-
getMinArgs
default int getMinArgs()Get minimum argument count 获取最小参数数量- Returns:
- the minimum argument count | 最小参数数量
-
getMaxArgs
default int getMaxArgs()Get maximum argument count 获取最大参数数量- Returns:
- the maximum argument count, -1 for unlimited | 最大参数数量,-1表示无限
-
isValidArgCount
default boolean isValidArgCount(int argCount) Check if argument count is valid 检查参数数量是否有效- Parameters:
argCount- the argument count | 参数数量- Returns:
- true if valid | 如果有效返回true
-