What happens when two different annotations have the same name?

advertisements

I never encountered the case and now I'm wondering: what happens when/if two different annotations have the same name? (I'll give here an example using an annotation provided by IntelliJ but the question is really generic so I'm not tagging it 'IntelliJ')

For example the first sentence here:

http://youtrack.jetbrains.net/issue/IDEABKL-4959

says:

Many libraries have their own @NotNull annotations (intellij, hibernate-validation, ..).

What happens exactly if I wanted to use, say, both IntelliJ's @NotNull and Hibernate's @NotNull? (once again @NotNull is just an example where I happen to find a clash)

Are they incompatible? If they're incompatible, is it for the whole project?

This is something I'm really not familiar with...


There is no ambiguity, because the annotation's package name will be specified in an import or on the annotation itself.

JSR-305 addresses your specific example. It seeks a standard set of annotations, and refers specifically to FindBugs' and IntelliJ's nullability annotations.

Nullness annotations (e.g., @NonNull and @CheckForNull). Both FindBugs and IntelliJ already support their own versions of nullness annotations.