IntelliJ建议在下面的程序中导入com.sun.istack.internal.NotNull
@Nothingannotation(这是错误的):
public class Test implements Comparable<Test> {
@Override
public int compareTo(@NotNull Test o) {
return 0;
}
}
字符串
当尝试正确的导入com.intellij.annotations.NotNull
(我认为)时,它看起来找不到类:
x1c 0d1x的数据
5条答案
按热度按时间5q4ezhmt1#
在添加注解之前,您可以在警告上按Alt+Enter,按下Right,选择Edit Inspection Settings,然后选择Configure Annotations并指定要插入的注解。
cnwbcb6i2#
从代码中删除导入。IntelliJ将要求您再次导入它。它应该建议有多个选项可用。您想要的注解应该在列表中。
gpnt7bae3#
我发现必须在Java项目的
build.gradle
文件中添加以下依赖声明,才能导入org.jetbrains.annotations.NotNull
和org.jetbrains.annotations.Nullable
注解,而不是com.sun.istack.internal.NotNull
和com.sun.istack.internal.Nullable
注解:字符串
bweufnob4#
对于更高版本的Intellij,使用
Cmd+Shift+A
(在MacOS上)调出Find Actions
菜单,然后键入Configure annotations
,选择建议以调出Compiler
首选项窗口。然后点击
Add runtime assertions for notnull-annotated methods and parameters
选项旁边的Configure annotations
按钮。然后它会弹出Noncalling和Nullable配置默认值列表。选择您想要的默认值,然后使用复选按钮将其设置为默认值。xyhw6mcr5#
这里有一个简单的方法来解决这个问题:导入org.jetbrains.annotations。注意:ans:尝试导入相关的依赖项
字符串