如何阻止 IntelliJ 在 Java 中自动导入 org.jetbrains.annotations?

How to stop IntelliJ from automatically importing org.jetbrains.annotations in Java?

我的 superclass 有一个方法签名,其参数使用 javax 注释,如下所示:

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class Nanana {

    // ...

    protected abstract void nanaFunction(
        @Nonnull final Parameter parParameter1,
        @Nullable final Parameter parParameter2
    ) { /* ... */ }
}

当我在另一个文件中继承此 class 而无需手动导入注释时,它会像这样自动完成我的覆盖(注意注释导入):

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ConcreteNanana extends Nanana {

    // ...

    @Override
    public void nanaFunction(
        @NotNull final Parameter parParameter1,
        @Nullable final Parameter parParameter2
    ) { /* ... */ }
}

如何配置 IntelliJ 以导入与 superclass 相同的注释?我正在使用 IntelliJ 2020.3.3 Ultimate。

如前所述here

这是一个缺陷,您可以通过以下方式解决:

Settings --> Inspections --> Java --> Probable bugs --> Nullability problems --> @NotNull/@Nullable problems --> Configure Annotations

并设置默认值

javax.annotation.Nullable
javax.annotation.Nonnull

重启应该就可以了

IntelliJ IDEA 2021.2.1 中的@Nonnull/@Nullable 注解配置:

Menu 
> File
  > Preferences
    > Editor
      > Inspections

Inspections
> Java
  > Probable bugs
    > Nullability problems
      > @NonNull/@Nullable problems

@NonNull/@Nullable problems
> Options
  > Configure annotations
    > Select preferred `Nullable` annotation
    > Press micro-accept button (see screenshot, horrible UX)
    > Select preferred `Nonnull` annotation
    > Press micro-accept button
  > Ok
>Ok

No restart needed