英文:
checker-framework incompatible types in type argument
问题
我有一些类似这样的代码,我在其中将一个映射存储到Java的ThreadLocal中,
import java.util.*;
class Foo {
private final ThreadLocal<Map<String, String>> barMap = ThreadLocal.withInitial(HashMap::new);
}
当我从checkerframework启用nullness检查时,我得到了以下错误
错误: [type.argument.type.incompatible] 类型参数中的类型不兼容。
找到: @Initialized @NonNull Map<@Initialized @NonNull String, @Initialized @NonNull String>
需要: [extends @Initialized @Nullable Object super null]
我不明白如何解决这个问题。
英文:
I have some code like this where I store a map to java threadlocal,
import java.util.*;
class Foo {
private final ThreadLocal<Map<String, String>> barMap = ThreadLocal.withInitial(HashMap::new);
}
when enabling the nullness check from checkerframework I get
Error: [type.argument.type.incompatible] incompatible types in type argument.
found : @Initialized @NonNull Map<@Initialized @NonNull String, @Initialized @NonNull String>
required: [extends @Initialized @Nullable Object super null]
I don't understand how to resolve this.
答案1
得分: 1
这是Checker Framework中的一个已知问题。您应该抑制这个警告。
Checker Framework目前使用的是Java 7的类型推断算法。Java 8对类型推断进行了重大更改,这要求在Checker Framework中进行重新实现。(Checker Framework本质上是一个独立的编译器。)这个重新实现已经部分完成,但尚未完成。
英文:
This is a known bug in the Checker Framework. You should suppress the warning.
The Checker Framework currently uses the Java 7 type inference algorithm. Java 8 made a major change to type inference, which requires a re-implementation in the Checker Framework. (The Checker Framework is essentially a compiler in its own right.) That re-implementation is partly done, but has not yet been completed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论