> ## Documentation Index
> Fetch the complete documentation index at: https://fluxon.tabooproject.org/llms.txt
> Use this file to discover all available pages before exploring further.

# 运行时注解与可选参数

> @Optional、@Export 等注解在 runtime-core 中的作用

运行时仅暴露少量注解用于描述导出方法的语义，供导出桥接与可选参数使用。

这些注解主要位于
[`core/src/main/java/org/tabooproject/fluxon/runtime/java`](https://github.com/TabooLib/fluxon/tree/master/core/src/main/java/org/tabooproject/fluxon/runtime/java)。

它们会被 `ExportRegistry` 扫描并生成扩展函数（见 [@Export 与桥接](/developer/export-bridge)）。

## `@Export`

* 标记方法可被 `ExportRegistry` 导出为扩展函数（`target::method(...)`）。
* 支持声明线程语义：
  * `@Export(async = true)`：注册为异步扩展（调用返回 `Future/CompletableFuture`）。
  * `@Export(sync = true)`：注册为主线程扩展（派发到 `FluxonRuntime#setPrimaryThreadExecutor(...)`）。

<Note>`@Export` 的 `async/sync` 仅影响注册时选择的函数类型；方法本身不需要返回 `Future`。</Note>

## `@Optional`

* 作用于参数，表示该参数及其后续参数为可选参数（建议仅用于尾部参数）。
* `ExportRegistry` 会基于 `@Optional` 生成“支持的参数数量列表”，便于脚本短参调用。

示例：

```java theme={null}
@Export
public String encode(String text, @Optional String charset) { ... }
```

生成的参数个数列表为 `[1, 2]`，脚本可传 1 或 2 个参数。

## 这些注解不会做什么

* 它们不会自动把方法“注册到运行时”。你仍需要在启动时调用 `ExportRegistry#registerClass(...)`。
* 它们不会替代类型转换：参数类型校验发生在调用期（`Intrinsics.checkArgumentTypes(...)`），必要时请在方法内部自行转换/容错。

## 与调用时的关系

* 参数个数列表会影响解析与调用：缺少必需参数会在解析/执行阶段报错。
* 类型校验由桥接器在调用前统一执行（`Intrinsics.checkArgumentTypes(...)`）。
  错误类型与手写扩展保持一致（如 `ArgumentTypeMismatchError`）。

## 相关链接

* [@Export 与桥接](/developer/export-bridge)
* [运行时配置与调试](/developer/runtime-config)
* [函数与异步](/language/functions-and-async)
