Dónal
Dónal

Reputation: 187529

java annotations - library or language feature?

Should Java annotations be considered a language or library feature. I don't mean the very concept of annotations which is obviously a language feature, but specific annotations such as @Override and @Deprecated?

It seems clearer that annotations supported only by 3rd-party libraries (e.g. Hibernate annotations) are clearly not part of the Java language, but for the built-in annotations I'm not so sure.

If this is considered too discursive, feel free to move to programmers.stackexchange.com

Upvotes: 4

Views: 409

Answers (3)

Matt Ball
Matt Ball

Reputation: 359786

Here's how I think about it:

boolean isLanguageFeature(foo)
{
    return JLS.contains(foo)
}

The JLS describes Java the programming language. As you clearly understand, the concept of annotations is a language feature. On the other hand, there are tons of standard Java library features which are not described by the JLS, such as the Collections APIs.

From JLS §9.6.1, Predefined Annotation Types:

Several annotation types are predefined in the libraries of the Java platform. Some of these predefined annotation types have special semantics. These semantics are specified in this section. This section does not provide a complete specification for the predefined annotations contained here in; that is the role of the appropriate API specifications. Only those semantics that require special behavior on the part of the Java compiler or virtual machine are specified here.

Thinking along those lines, then, I'd say that Java annotations are a library feature.

Upvotes: 4

Dave Newton
Dave Newton

Reputation: 160191

Annotations like @Deprecated and @Override are library features that happen to be used by the language tools to enforce and/or describe code behavior. Definitely library features.

Upvotes: 2

Annotations are used (in Java) for adding meta data to your code. Annotations are the way to write readable and maintainable code. Therefore to write good code use annotations weather they are Java annotations or any other third party.

for e.g. like to make an EJB stateless now you just need to add @Stateless annotation.

Upvotes: -2

Related Questions