Philipp Claßen Philipp Claßen - 1 month ago 6
Java Question

Is there a @NonNullByDefault annotation in IDEA?

Eclipse has the

@NonNullByDefault
annotation, which treats all values as
@NonNull
unless you explicitly annotate them as
@Nullable
.

Is there an equivalent option in IntelliJ IDEA, or do you have to always use
@Nonnull
?

Answer

No, it is currently not supported by IDEA.

As a proof, see lena's link about the open feature request to allow 'NotNull' as the default element behavior for a given class or package.

Maybe a similar feature will be become standard with JSR-305, which may include the @ParametersAreNonnullByDefault annotation and also the opposite annotation @ParametersAreNullableByDefault. Note that in contrast to @NonNullByDefault, return values are not covered by those two annotations. So, you still had to annotate the return value explicitely.

All that doesn't change the current state, though. Neither has JSR-305 become a standard, nor does IDEA implement it.

Comments