Hibernate Search, Hibernate, Struts2… I see more examples… In same examples I see the annotation on the field.. Other on the get/set method.. There are differences? Or is casual..
I hope that is not a stupid question!
Saluti!
Luigi
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The difference depends on the annotation and how it is used. For example, in Spring you can use the
@Controllerannotation only on a class. This tells Spring that the class is a controller.As far as methods are concerned,
@RequestMappingis an annotation that goes on a method. For properties, you can have validation annotations like@NotNull(in Hibernate validator).Annotations are definitely not casual; they carry meaning and can affect the way the code behaves.
From the Java documentation regarding annotations:
You can specify what an annotation can annotate by specifying the the elements (using a
@Targetannotation) when you define your own annotation.