Class SealedDispatcher.Builder<T,R>
java.lang.Object
cloud.opencode.base.reflect.sealed.SealedDispatcher.Builder<T,R>
- Type Parameters:
T- the sealed type | 密封类型R- the result type | 结果类型
- Enclosing class:
SealedDispatcher<T,R>
Builder for SealedDispatcher
SealedDispatcher 构建器
Registers handlers for each permitted subclass and validates exhaustiveness at build time.
为每个许可子类注册处理器,并在构建时验证穷举性。
- Since:
- JDK 25, opencode-base-reflect V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the dispatcher 构建分发器<S extends T>
SealedDispatcher.Builder<T, R> Registers a handler for a specific subtype 为特定子类型注册处理器Registers a default handler as fallback 注册默认处理器作为回退
-
Method Details
-
on
public <S extends T> SealedDispatcher.Builder<T,R> on(Class<S> subtype, Function<? super S, ? extends R> handler) Registers a handler for a specific subtype 为特定子类型注册处理器- Type Parameters:
S- the subtype | 子类型- Parameters:
subtype- the subtype class | 子类型类handler- the handler function | 处理函数- Returns:
- this builder | 此构建器
- Throws:
OpenReflectException- if subtype is not assignable from sealed type | 如果子类型不可从密封类型赋值
-
orElse
Registers a default handler as fallback 注册默认处理器作为回退When a default handler is provided, exhaustiveness checking is skipped at build time.
当提供默认处理器时,构建时跳过穷举性检查。
- Parameters:
defaultHandler- the default handler | 默认处理器- Returns:
- this builder | 此构建器
-
build
Builds the dispatcher 构建分发器If no default handler is registered, validates that all concrete leaf classes in the sealed hierarchy have handlers. Throws
OpenReflectExceptionif any are missing.如果未注册默认处理器,验证密封层次结构中的所有具体叶类都有处理器。 如果有缺失则抛出
OpenReflectException。- Returns:
- the built dispatcher | 构建的分发器
- Throws:
OpenReflectException- if exhaustiveness check fails | 如果穷举性检查失败
-