如何解决问题检查器框架Null检查器和lambda
示例Java代码:
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.function.Supplier;
public abstract class LambdaTest {
abstract <@Nullable R> @Nullable R invoke(Supplier<R> func);
void test() {
invoke(() -> null);
invoke(() -> "123");
}
}
使用无效性检查器(版本3.7.1)进行检查时会产生以下错误:
[ERROR] LambdaTest.java:[10,11] [type.argument.type.incompatible] incompatible type argument for type parameter R extends @Initialized @Nullable Object of invoke.
[ERROR] found : @Initialized @NonNull Object
[ERROR] required: [extends @Initialized @Nullable Object super null]
[ERROR] LambdaTest.java:[10,18] [return.type.incompatible] incompatible types in return.
[ERROR] type of expression: null
[ERROR] method return type: @Initialized @NonNull Object
[ERROR] LambdaTest.java:[11,11] [type.argument.type.incompatible] incompatible type argument for type parameter R extends @Initialized @Nullable Object of invoke.
[ERROR] found : @Initialized @NonNull String
[ERROR] required: [extends @Initialized @Nullable Object super null]
用<@Nullable R>
替换<R>
会导致:
[ERROR] LambdaTest.java:[10,18] [return.type.incompatible] incompatible types in return.
[ERROR] type of expression: null
[ERROR] method return type: @Initialized @NonNull Object
- 为什么删除上限
@Nullable
时结果会有所不同,我认为这是默认设置? - 为什么总有错误?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。