Java annotations

Just wondering about the performance implications of annotations as I’m looking to use them for general usage.
What do you guys think about annotations? Have they been useful to you? Are you using them when you can?

As far as I know, annotations are compile-time constructs, and they should not impact runtime performance at all. Of course, I could be wrong :wink:

There are two annotations that I use, the first more often than the second: @Override and @SuppressWarnings. @Override I use regularly to denote methods that override superclass methods. This has helped me catch refactoring errors, where I have changed classes into interfaces, for example. Eclipse can generate warnings when you forget an @Override annotation. I have also used @SuppressWarnings within Eclipse when I do not want to be bothered about the lack of serializable classes’ definitions of serialVersionUID.

Ther really are two kidsn of annotiations

There are the “pragma-ish ones” you mentio nwhich are compierl directives, and there are the general annotions. General annotations are basically a way of tagging “user information” to a class and passing it through from the compiler to the run-time.

They add some data to the class, which increases the in-mewmory class size at run time by at least a few bytes. Beyind that I cant imagine they have much of an impact.

Now hoe fast they are to access at run-time is probably VERY VM dependant.

I’ve been trying to use annotations as runtime RTTI.
I feel that performance impact wouldn’t be as high as using reflection.