Sunday 22 February 2015

Why use annotation? OR benefits of annotation in java ?

Meta data is some kind of description that you can supply along with your data. In java its possible to do with annotations, XML, there are other methods.

In order to take advantage of meta data you should have something that will process this data and decide what happens once the meta data is recognized.

Annotations have a lot of advantages over XML, to name a few :

Static type checking - the compiler will check for you where the annotation (once defined properly) is applicable and how

Clean code - its much easier to see (visually) the meta data defined in annotations

However it comes at a price:

XML doesn't require recompilation when you want to change something. With annotation you'll have to recompile.

No comments:

Post a Comment