IntelliJ suggests wrong @NotNull annotation

我怕爱的太早我们不能终老 提交于 2019-12-10 14:20:05

问题


IntelliJ is suggesting to import com.sun.istack.internal.NotNull the @NotNull annotation (which is wrong) in the following program:

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

When trying the correct import com.intellij.annotations.NotNull (I think) it looks like it can't find the class:


回答1:


You can Alt+Enter on the warning before you add the annotation, press Right, choose Edit Inspection Settings, then Configure Annotations and specify the annotation you want to be inserted there.




回答2:


Remove the import from the code. IntelliJ will ask you to import it again. It should suggest that there are multiple choices available. The annotation you want should be in the list.




回答3:


I found I had to add the following dependency declaration to my Java project's build.gradle file before I was able to import the org.jetbrains.annotations.NotNull and org.jetbrains.annotations.Nullable annotations rather than the com.sun.istack.internal.NotNull and com.sun.istack.internal.Nullable annotations:

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.jetbrains:annotations:15.0'
}


来源:https://stackoverflow.com/questions/31243474/intellij-suggests-wrong-notnull-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!