aspose file tools*
The moose likes Java in General and the fly likes Annotations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Annotations" Watch "Annotations" New topic
Author

Annotations

sudharshan tettu
Ranch Hand

Joined: Jul 17, 2006
Posts: 124
I would like to know how annotation works are there any good article about writing our own annotation in java or to know the working of annotations
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
You can start with the Java Tutorials, but the last time I looked the annotations article was very brief.
There is a lot in Thinking in Java 4/e by Bruce Eckel about annotations.

[edit]Mend broken link[/edit]
[ November 06, 2008: Message edited by: Campbell Ritchie ]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Altho there are some folks who think annotations are evil. They make the code ugly. YMMV
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

No they don't. That's the same as saying "Javadoc makes the code ugly". They are both similar in that they provide extra information on your classes, fields, methods et all. The biggest difference is that Javadoc is not included in the byte code and annotations are, and can be queried.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Originally posted by Rob Prime:
No they don't. That's the same as saying "Javadoc makes the code ugly".


Er, no, you can't say that either.

Perhaps it would be more precise if I had written:
"I don't like annotations because I think they make the code more ugly than their value."

Its a personal opinion, you can have your own opinion, but you can't say that I don't think they are ugly or too ugly to use.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Now, now, Pat.

You never said "I think they look ugly." Rob was replying to the exact form of what you posted.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

Exactly.

But since it is your opinion that annotations make code ugly, can you mention why?

I agree that it makes it a bit harder to read if you put the annotation on the same line as the code:

That's why I always put them one line higher:

Do you really think that is so much uglier?
Mike Stach
Greenhorn

Joined: Oct 26, 2008
Posts: 8
Moreover, when you start using frameworks like Spring, you will find simple annotations can make life so much easier that you can avoid writing a lot many helper classes that people write using old-fashioned java.

Annotations are used quite a bit in popular frameworks and I feel they do not make code ugly but more informative.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

I'd argue that beauty is in the eye of the beholder. Pat didn't say Annotations don't work or they add no value. Pat said they are ugly. Pat is allowed to have his opinion. I seriously doubt that showing Pat an example of what he's more than likely already seen is going to make him instantaneously change his mind.

Of course, none of this has much to do with the OP's question anyway so let's get back on topic. If you guys want to argue what is pretty and what isn't you might consider starting a new thread.


GenRocket - Experts at Building Test Data
sudharshan tettu
Ranch Hand

Joined: Jul 17, 2006
Posts: 124
thank you all for your quick reply
sudarsan tettu
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Originally posted by sudarsan tettu:
thank you all for your quick reply
sudarsan tettu


You're welcome. I hope it was actually helpful
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Annotations