Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why annotate formal parameter?

 
Tapio Niemela
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, I'm puzzled with annotating method formal parameters. I understand annotating classes and methods themselves.
Client using/calling those classes can use reflection to find out which "flags" have been set to the inspected class. I also understand it for methods (like Springs @Transactional). But I can't seem understand the usage for method parameters, for example @PathVariable with Spring mvc. I already tried to search answers from this site and from google, but answers are more like "how", instead of "why"..

Knowing the good folks here, could someone enlighten me? Please, give some simple examples where (and why) to annotate method parameters, also some code example from the client calling that method would be great..
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure, which part isn't clear. For e.g. consider the PathVariable documentation in the spring doc, the part in bold below talks about where and why its used ...

To access parts of a request URL in your handling methods, use the URI templates in the @RequestMapping path value.
Use the @PathVariable method parameter annotation to indicate that a method parameter should be bound to the value of a URI template variable.


http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic