Java News from Tuesday, December 11, 2007

Michael Ernst has posted the early draft review specification of JSR 308: Annotations on Java Types . Quoting from the spec,

JSR 308 proposes an extension to Java’s annotation system [Bra04a] that permits annotations to appear on any use of a type. (By contrast, Java SE 6 permits annotations to appear only on class/method/field/variable declarations; JSR 308 is backward-compatible and continues to permit those annotations.) Such a generalization removes arbitrary limitations of Java’s annotation system, and it enables new uses of annotations.

This proposal also notes a few other possible extensions to annotations (see Section D). This document specifies the syntax of extended Java annotations, but it makes no commitment as to their semantics. As with Java’s existing annotations [Bra04a], the semantics is dependent on annotation processors (compiler plug-ins), and not every annotation is necessarily sensible in every location where it is syntactically permitted to appear. This proposal is compatible with existing annotations, such as those specified in JSR 250, “Common Annotations for the Java Platform” [Mor06], and JSR 305, “Annotations for Software Defect Detection” [Pug06]. (For a comparison of JSR 305 and JSR 308, see Section D.4.3, page 25.)

This proposal does not change the compile-time, load-time, or run-time semantics of Java. It does not change the abilities of Java annotation processors as defined in JSR 269 [Dar06]. The proposal merely makes annotations more general — and thus more useful for their current purposes, and also usable for new purposes that are compatible with the original vision for annotations

Here's an example from the spec:

class DAG {

  Set<Edge> edges;

 // ...

 List<Vertex> getNeighbors(@Interned @Readonly Vertex v) @Readonly {
 List<Vertex> neighbors = new LinkedList<Vertex>();
 for (Edge e : edges) {
   if (e.from() == v) neighbors.add(;
 return neighbors;


I don't know. I could see how this could be useful, but it also make signatures even harder to read. I haven't yet made up my mind whether the benefits of this proposal outweigh the costs.