Why is it important? what are advantage according to XML mapping? Can you explan these? thank you.
+8
A:
It is not something important as in "mandatory". It's a different possibility, with strength and weaknesses.
Advantages:
- Compile-time checking : writing in Java (instead of Xml) is very user-friendly in the IDE nowadays. No more typos discovered when starting your application (incremental compilation), not that much to remember (completion)...
- Localized with the code (class level) : instead of having to open two files (java and xml) to get the full story, with one annotated java file, you open only one file. This is less repetitive, faster in the long run.
- Localized with the code (method or field level) : because the annotation go on a method (or field), there is no need to specify the method it belongs to. That redondant information is not given, which is shorter, and always coherent (even after a code refactoring for example). Maintenance is so much faster.
- Tools (javadoc, other tools using reflection) can use the annotations for some other requirements.
- Annotations are newer than the xml, the team used the input they had received at the time to provide better default values. Xml has some, but can't change much for compatibility reasons. Often, with the annotations technology, you write no annotation at all, and it works. Imagine the time-saving, especially during development.
KLE
2009-09-02 11:43:55
"no more tipos"... oh, the irony...
skaffman
2009-09-02 11:58:23
@skaffman: fixed it. Hope my revision comment makes you even happier :-)
Robert Munteanu
2009-09-02 12:03:32
@Robert thanks for the revision, I was going to do it myself.
KLE
2009-09-02 12:10:25
@skaffman I actually liked your comment, made me laugh :-) As you might have partly guessed, I'm a foreigner (french actually, sorry for that ;-) ), with rather poor english skills. I wish I could let the typo in the message, so that your comment makes sense, while still giving the correct spelling ... How ?
KLE
2009-09-02 12:13:16
thank you very much.
stical
2009-09-02 12:15:44
@KLE: excellent answer, no need to worry about typos - that's one of the nice things about SO.
Robert Munteanu
2009-09-02 12:47:28