Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annotations

 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48444
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Altho there are some folks who think annotations are evil. They make the code ugly. YMMV
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48444
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all for your quick reply
sudarsan tettu
 
Campbell Ritchie
Sheriff
Posts: 48444
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sudarsan tettu:
thank you all for your quick reply
sudarsan tettu


You're welcome. I hope it was actually helpful
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic