File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Why annotate formal parameter? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why annotate formal parameter?" Watch "Why annotate formal parameter?" New topic
Author

Why annotate formal parameter?

Tapio Niemela
Ranch Hand

Joined: Jan 06, 2006
Posts: 77
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

Joined: Feb 08, 2009
Posts: 605

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

Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why annotate formal parameter?