[JSR308] Postfix syntax for type annotations

Michael Ernst mernst at csail.mit.edu
Sun Feb 25 09:44:53 EST 2007

I am reopening the discussion of the postfix syntax for type annotations.

I presume that everyone has already read the discussion on the JSR 308
webpage, which used to appear in "resolved issues" but which I have moved
back into "open issues".  It would not be productive to make comments
without first reading that.  I have also appended it below my signature,
for reference.


[The following text is from http://pag.csail.mit.edu/jsr308/.]

Postfix syntax for type annotations

The current proposal uses a simple prefix syntax for type annotations: the
annotation appears before the type, as in @NonNull String. There are two
exceptions to this general rule: the syntax for arrays (which is still up
for debate) and the syntax for method receivers.

An alternative would use a simple postfix syntax for type annotations: type
annotations would appear after the type, as in String @NonNull. This
syntactically separates type annotations from all other annotations,
putting them in a different place in the syntax. In

        @A Type @B var;

@A would refer to the variable and @B would refer to the type.

Advantages: This reduces the number of special cases in the syntax by one
(no special case is needed for arrays), which may be less confusing to

Disadvantages: Programmers must remember which annotations are type
annotations and which are not, which may be confusing. The postfix syntax
introduces more new locations in a program where annotations may be placed
(the prefix syntax reuses existing locations for variable declarations
without ambiguity); in this sense, it feels like a bigger change to
Java. The postfix syntax is not backward-compatible: it is inconsistent
with existing annotations proposed by JSR 305, such as @NonNull.

More information about the JSR308 mailing list