Domanda

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?

È stato utile?

Soluzione 2

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.

Altri suggerimenti

Idea version 14 will include support for the JSR 305 "@TypeQualifierDefault" annotation, which allows the user to create a custom annotation, to be used on a package declaration in a package-info.java file, that specifies that everything in that package (not just parameters, but method return values, local variables, etc.) will be implicitly annotated as not allowing null values.

Unfortunately, this doesn't (currently) recursively affect subpackages, so each subpackage has to have a package-info.java file too, declaring that subpackage to use the annotation.

See here for details and an example of use:

http://youtrack.jetbrains.com/issue/IDEA-125281

Note that this is already implemented in Early Access Program (EAP) builds.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top