Using @NotNull in a project where both IntelliJ and Eclipse developers are working
A co-worker on IntelliJ IDEA (working on another project) showed me the amazing @NotNull annotation. I've read messages here on SO about h开发者_StackOverflow社区ow 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?
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.
I'd ask why one team doesn't use a common IDE. Why not standardize on one or the other? (You know which one I'd recommend that you go with.)
精彩评论