JSR-175

Posted in blog city on May 13th 2004  

I got some time to spend on the “meta-data/annotations feature” (JSR-175) that is part of JDK1.5. The whole concept of annotations is in general, good. However, to me, the way Java is implementing the concept seems patchy.

Declaring an annotation itself is ackward. Why should one use “an interface with restricted features” to declare an annotation? I wish there is a new key word such as “annotation” introduced into the language to declare annotations. Also, using method semantics to define the attributes for the annotation does not seem correct. This defies some common sense. The FAQs in the spec attempted to answer this, but the answers are far from satisfactory.

With respect to  local variable annotations — Imagine your annotation is declared with Retention policy of “CLASS” or “RUNTIME” and then the annotation is made on a local variable — the annotation can never make it to the class file and you can never introspect it. I guess this could have been better designed.

Package level annotations is again a mess. The spec says developers should write package-info.java file and not write any code in it (package-info is an illegal class name as per java specs). This is surely a clumsy way to deal with annotations at package level. The spec authors should have given more time for this to be resolved (in JDK1.5 beta “package level annotation feature” is not yet implemented, may be they are still wondering if there is a better way).

Overall, it clearly shows that annotations are an “after-thought” to the Java language.

One Response to “JSR-175”

  1. I totally hope Java doesn’t go the route of C++ and just try to stuff every feature into an already well-rounded language. Java doesn’t need this… and it’s making an exponential number of, ::cringe:: frameworks arise that do things that a language like Java shouldn’t necessarily do. I’m all for aspects… but then there’s dependency injection, (sounds like a switch back to a C-style way of programming) J2EE bean, WAR, EAR, SAR, etc… hell to deal with.

    Ugghhh, annotations might seem like a good idea, but I think they’re being used for everything they were not meant for.

Leave a Reply