Intellij Idea IntelliJ建议错误的@ Nothing注解

ztmd8pv5  于 2023-11-16  发布在  其他
关注(0)|答案(5)|浏览(241)

IntelliJ建议在下面的程序中导入com.sun.istack.internal.NotNull@Nothingannotation(这是错误的):

  1. public class Test implements Comparable<Test> {
  2. @Override
  3. public int compareTo(@NotNull Test o) {
  4. return 0;
  5. }
  6. }

字符串
当尝试正确的导入com.intellij.annotations.NotNull(我认为)时,它看起来找不到类:
x1c 0d1x的数据

5q4ezhmt

5q4ezhmt1#

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

cnwbcb6i

cnwbcb6i2#

从代码中删除导入。IntelliJ将要求您再次导入它。它应该建议有多个选项可用。您想要的注解应该在列表中。

gpnt7bae

gpnt7bae3#

我发现必须在Java项目的build.gradle文件中添加以下依赖声明,才能导入org.jetbrains.annotations.NotNullorg.jetbrains.annotations.Nullable注解,而不是com.sun.istack.internal.NotNullcom.sun.istack.internal.Nullable注解:

  1. repositories {
  2. mavenCentral()
  3. }
  4. dependencies {
  5. compile 'org.jetbrains:annotations:15.0'
  6. }

字符串

bweufnob

bweufnob4#

对于更高版本的Intellij,使用Cmd+Shift+A(在MacOS上)调出Find Actions菜单,然后键入Configure annotations,选择建议以调出Compiler首选项窗口。
然后点击Add runtime assertions for notnull-annotated methods and parameters选项旁边的Configure annotations按钮。然后它会弹出Noncalling和Nullable配置默认值列表。选择您想要的默认值,然后使用复选按钮将其设置为默认值。

xyhw6mcr

xyhw6mcr5#

这里有一个简单的方法来解决这个问题:导入org.jetbrains.annotations。注意:ans:尝试导入相关的依赖项

  1. <dependency>
  2. <groupId>org.jetbrains</groupId>
  3. <artifactId>annotations</artifactId>
  4. <version>13.0</version>
  5. </dependency>
  6. </dependencies>

字符串

相关问题