问题
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