• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annotations

 
Arjun Reddy
Ranch Hand
Posts: 629
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am just learning about Annotations and I have a question. I wrote the following code looking at an example but I am trying to understand the meaning here and the whole purpose of doing so.

MyAnnotation.java

Test.java


I really don't understand the above code. Can someone please explain?/

Thanks.
[ November 28, 2008: Message edited by: Arjun Reddy ]
 
Arjun Reddy
Ranch Hand
Posts: 629
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody?/

Thanks.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What don't you understand? Annotations are simply a way to specify metadata through Java rather than something like XML. The first bit of code you show defines an annotation and its attributes.

The second part is how you use said annotation, although specifying an annotation on a main method is probably an odd example. In fact your entire example probably makes it more difficult to understand.

Additionally an annotation is useless without the code to process it. So by itself an annotation does nothing. Using the reflection API you can inspect classes and methods and determine what annotations exist. At that time is the work actually done.
[ November 29, 2008: Message edited by: Gregg Bolinger ]
 
Arjun Reddy
Ranch Hand
Posts: 629
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Gregg. It would be really helpful if you can give an example in code if possible.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arjun Reddy:
Thanks for the reply Gregg. It would be really helpful if you can give an example in code if possible.


Many people already have. Here is a good place to start:

http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html

Also, Google is your friend.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I will check that.

Thanks.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understood it now Gregg. Thanks for the link.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic