Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

annotations on getter methods in entity class - why?  RSS feed

 
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Copying this entity (not entity bean) from: http://java.sun.com/developer/technicalArticles/J2EE/intro_ee5/



I am just wondering that they are putting annotations (id, many to one etc) on getter methods. Why???

Isn't it better and cleaner to put these kind of annotations on variable (instead of methods)?

What's say?

Thanks.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put annotations on either field level OR method level. Most developers prefer annotating getter methods because otherwise method level annotations are overridden.
Sie also this blog.

Lars
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!