Reputation: 2298
My superclass has a method signature with parameters that use javax
annotations like so:
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class Nanana {
// ...
protected abstract void nanaFunction(
@Nonnull final Parameter parParameter1,
@Nullable final Parameter parParameter2
) { /* ... */ }
}
And when I inherit from this class in a different file without manually importing the annotations, it autocompletes my override like so (notice the annotation imports):
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
) { /* ... */ }
}
How do I configure IntelliJ to import the same annotations as the superclass? I am using IntelliJ 2020.3.3 Ultimate.
Upvotes: 5
Views: 1067
Reputation: 4591
@Nonnull/@Nullable annotations configuration in IntelliJ IDEA 2021.2.1:
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
Upvotes: 1
Reputation: 1004
As mentioned here
This is a defect and you can solve it by:
Settings --> Inspections --> Java --> Probable bugs --> Nullability problems --> @NotNull/@Nullable problems --> Configure Annotations
And Set the defaults
javax.annotation.Nullable
javax.annotation.Nonnull
Restart and should be ok.
Upvotes: 9