Two Laptop Bag
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

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: 607

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.

Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
I agree. Here's the link:
subject: Why annotate formal parameter?
It's not a secret anymore!