Early Draft Review of JSR-308, Annotations on Java Types is available For Review

20Nov07

JSR 308 proposes an extension to Java’s annotation system 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

Example

@NonNullDefault
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(e.to());
return neighbors;
}
}

Find out more about JSR 308 here