5

com.sun.istack.internal.NotNullIntelliJ 建议在以下程序中导入@NotNull 注释(这是错误的):

public class Test implements Comparable<Test> {
    @Override
    public int compareTo(@NotNull Test o) {
        return 0;
    }
}

当尝试正确的导入com.intellij.annotations.NotNull(我认为)时,它看起来找不到类:

在此处输入图像描述

4

4 回答 4

3

在添加注释之前,您可以在警告上 Alt+Enter,按 Right,选择 Edit Inspection Settings,然后选择 Configure Annotations 并指定要在其中插入的注释。

于 2015-07-06T15:54:40.900 回答
2

从代码中删除导入。IntelliJ 会要求您再次导入它。它应该表明有多种选择。您想要的注释应该在列表中。

于 2015-07-06T10:30:21.790 回答
2

我发现我必须先将以下依赖项声明添加到我的 Java 项目build.gradle文件中,然后才能导入org.jetbrains.annotations.NotNullandorg.jetbrains.annotations.Nullable注释而不是com.sun.istack.internal.NotNullandcom.sun.istack.internal.Nullable注释:

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.jetbrains:annotations:15.0'
}
于 2017-03-28T20:58:39.253 回答
0

对于更高版本的 Intellij,使用Cmd+Shift+A(在 MacOS 上)调出Find Actions菜单,然后键入Configure annotations,选择建议以调出Compiler首选项窗口。

然后单击Configure annotations选项旁边的按钮Add runtime assertions for notnull-annotated methods and parameters。然后它将显示 NonNull 和 Nullable 配置默认值列表。选择您想要的默认值,然后使用复选按钮将其设置为默认值。

于 2020-11-19T09:02:39.497 回答