2

I know java annotation is a powerfull tool. For me, project lombok is a great example of extreme use. But i've heard that sometimes, it is better not to use annotations.

Can you give me examples of bad annotations, so i have an idea of what to avoid ?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236
  • 2
    maybe this will help you: http://stackoverflow.com/questions/1108959/what-are-the-pros-cons-of-annotations-non-compiler-compared-to-xml-config-files – MByD Aug 23 '11 at 13:45
  • Where did you heard that? In what context? ...without being more specific, it seems difficult to answer properly. – dagnelies Aug 23 '11 at 13:47
  • a little more context would help here. Annotations are helpful to use at some places e.g. in JUnit classes to avoid method naming conventions. But sometimes, like in Spring controllers, I find DI through xml config to be a better choice as against annotations as it takes out the config part outside your class. I would say it depends on your usecase. – Ash Aug 23 '11 at 13:50

1 Answers1

2

It's like asking in which situations a spoon isn't useful.

Instead it can typically beneficial to use annotations when

  • You're constructing a framework which will be used by many components.

    • For instance I once made a gui framework and added annotations such as @CSS etc.
    • Hibernate provides in my opinion a great approach to annotation based database mapping
  • You need to perform some compile-time task, like generating javadoc.

  • Dependency injection
Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148