A co-worker on IntelliJ IDEA (working on another project) showed me the amazing @NotNull annotation. I've read messages here on SO about how starting to add @NotNull everywhere saved lots of time and headaches (and IntelliJ 10 can even add automatically @NotNull to old code when it detects that null would wreak havoc).
Since I read my first "Probable @NotNull violation" message (in real-time, in the IDE, even on a partial .java file that doesn't compile yet) my jaw dropped and I got hooked.
So I was wondering: is there anything that needs to be known if we want to start using @NotNull in a project where developers are using both Eclipse and IntelliJ?
I know IntelliJ ships with the annotations.jar. Is this compatible with Eclipse?
@NotNull The @NotNull annotation is, actually, an explicit contract declaring that: A method should not return null. Variables (fields, local variables, and parameters) cannot hold a null value.
@NonNull – The compiler can determine cases where a code path might receive a null value, without ever having to debug a NullPointerException. @ReadOnly – The compiler will flag any attempt to change the object.
The @NonNull annotation generates a null check for fields and arguments annotated with this annotation. This annotation can be used on fields, constructor arguments, and method arguments.
There is also the possibility to store the annotations outside of the source. Settings > Code Style > Code generation > Use external annotations. The annotations are then stored in an annotations.xml file instead of in the source. That way Eclipse users never have to see the annotations. The location of the annotations.xml can be configured and it is probably best to store the file with the project in version control.
See
http://www.jetbrains.com/idea/webhelp/using-external-annotations.html http://blogs.jetbrains.com/idea/2008/02/external-annotations/
You can use annotations.jar
with Eclipse, but you probably won't get any benefits... See this SO post.
You could support both IDEs with FindBugs's @NonNull and related IDE plugins.
Findbugs has similar functionality, but the integration is a pale shadow of IntelliJ's built in power.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With