Early plans for extensive annotations in Java SE 8
An early draft review of JSR 308 shows the fight for some new Java schematics – annotations everywhere!
In recent weeks, we’ve seen a flurry of JSRs appear with some bright early ideas on where we may be heading for Java SE 8 over the next year of development. Java spec lead Alex Buckley has stepped up with his JSR 308 Early Draft Review, which could bring about some fundamental changes to the language.
Buckley reveals that JSR 308 plans to extend the Java language in Java SE 8 so that annotations may appear on essentially any use of a type. This is a shift away from the generalising SE 7 that permits annotations only on declarations, enabling new uses such as the Checker framework. JSR 308 will still be backward-compatible, though, and continues to permit those annotations.
Also present with the Early Draft is information regarding
class file support and sketches showing interactions with
other language features planned for Java SE 8. APIs
for reflection (
java.lang.reflect) and annotation
processing (JSR 269’s
javax.lang.model) will be
included within the next milestone review. Reference implementation
will also shift across to OpenJDK alongside this.
The document speciﬁes the syntax of extended Java annotations, but it makes no commitment as to their semantics, given that this is still dependent on compiler plugins. Within the PDF, Buckley covers some of the changes that he wishes to be implemented for Java SE 8 and reveals the key drivers for that decision, saying:
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 deﬁned in JSR 269. 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.
JSR 308 does not extend Java to allow annotations on type names that are not type uses, such as the type names that appear in import statements, class literals, static member accesses, and annotation uses.
It is worth checking out the document in full to see just some of the thinking behind Buckley’s proposals. There’s some interesting changes afoot for Java 8.