docs: update kavaref-core

This commit is contained in:
2025-06-29 02:02:05 +08:00
parent b1a2097756
commit 770f253861
2 changed files with 35 additions and 0 deletions

View File

@@ -489,6 +489,25 @@ but we **do not recommend this**, which will mask the problem unless it is neces
If you set `optional()`, please do not use `firstMethod`, `firstConstructor` and other methods to get a single result.
Because they throw an exception with empty list when there is no result, you can use the method with the suffix `OrNull` to get a single result.
But one thing you need to pay attention to here is that if you do not set `optional()`,
then methods such as `firstMethodOrNull` will still throw exceptions when there is no result**, which is the expected behavior because `method { ... }`
This is the "build" operation of the filter. Exceptions are handled here.
Methods such as `firstMethodOrNull` are just an encapsulation.
It is an exception handling of Kotlin's own standard library whether the result `List` is empty. It does not participate in exception handling of KavaRef filters.
So you must do it like the following.
> The following example
```kotlin
Test::class.resolve()
// Set optional conditions.
.optional()
.firstMethodOrNull {
name = "doNonExistentMethod"
} // Return MethodResolver or null.
```
:::
### Log Management

View File

@@ -474,6 +474,22 @@ No method found matching the condition for current class.
如果你设置了 `optional()`,那么请不要使用 `firstMethod`、`firstConstructor` 等方法来获取单个结果,
因为它们会在没有结果时抛出列表为空的异常,你可以使用后缀为 `OrNull` 的方法来获取单个结果。
但是这里需要注意一个事情,**如果你没有设置 `optional()`,那么 `firstMethodOrNull` 等方法依然会在没有结果时抛出异常**,这是预期行为,因为 `method { ... }`
才是过滤器的 “构建” 操作,异常在此处理,`firstMethodOrNull` 等方法只是一个封装,是对结果 `List` 是否为空的 Kotlin 自身标准库异常处理,不参与 KavaRef 过滤器的异常处理。
所以你一定要像下面这样做。
> 示例如下
```kotlin
Test::class.resolve()
// 设置可选条件
.optional()
.firstMethodOrNull {
name = "doNonExistentMethod"
} // 返回 MethodResolver 或 null
```
:::
### 日志管理