为什么我会从 IntelliJ 中的“NullableProblems”检查中收到警告:
public class Test implements Comparable<Test> {
@Override
public int compareTo(Test o) {
return 0;
}
}
我正在使用 IntelliJ 14.1.4 并使用 Java 1.7 进行编译
截图:
在参数前添加 @NotNull
没有帮助:
最佳答案
来自Comparable.compareTo
:
@throws NullPointerException if the specified object is null
所以 IntelliJ 知道,该对象不应该是 null
并添加 @NotNull
注释 automatically :
IntelliJ IDEA will look carefully at SDK and libraries bytecode and will infer these annotations automatically so that they can later be used to analyze source code to spot places where you overlooked null.
您的覆盖方法不包含此注释,因此它覆盖此行为使参数可为空 - 违反 Comparable
接口(interface)的约定。
您可以通过在参数前添加 @NotNull
来解决此问题。
您也可以通过按 Alt + Enter 来禁用此检查,在弹出菜单中选择警告并在子菜单中选择 Disable Inspection
-菜单。
查看 Web Help和 this thread有关 @NotNull
/@NonNull
注释的更多信息。
关于java - IntelliJ 中的检查警告 "NullableProblems"不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31242459/