Annotations are one of the big new features in Java. Annotations are intended to reduce the amount of XML we might otherwise use. In his blog, Rob Breidecker writes about when he would choose to use an annotation and when XML may still be the best choice. He starts his blog out with this modest statement before listing his guidelines.
I’ve been using annotations (as well as Java 5), for about six or seven months now, so by no means am I an expert. I thought it would be interesting to research the topic and develop a list of when to and not to use annotations and XML
The separation in the lists revolves around two themes, the static nature of your metadata and the scope to which it applies. In Rob’s estimation, Annotations work best when the metadata is fairly static and the scope in which it is applied is very narrow. XML is still suited for more dynamic metadata that has a broad reach with-in your code. Rob cites EJB3 as a good example of how to combine XML and Annotations.
EJB3 uses annotations to set nearly all of its features where it makes sense, and XML can be used to provide alternate implementations and overrides if necessary or when annotations aren’t appropriate.
He ends the entry asking for comments on his list. Where do you see Annotations being used instead of XML?