[JSR308] Postfix syntax for type annotations

Michael Ernst mernst at csail.mit.edu
Tue Jan 30 20:29:46 EST 2007


> Just joining the discussion and mailing list, I'd like to introduce myself:
> Neal Gafter from Google. Please pardon me if I ask dumb questions, as I
> haven't been listening.

Welcome.  You can see the archives at 
The welcome message you received when you joined the list gave this URL.

Incidentally, I have also changed the subject line of your message from
"Hello, and a comment", so that it's easier for everyone (including those
reading the archives) to understand what is being discussed.  It would be
great if everyone on the list could help out in this way.

> I read the draft spec (and an earlier version), and it seems much more
> complex than it needs to be to accomplish its goals.  The simplest syntax
> would be to annotate a type by placing the annotation after the type. This
> works for arrays, arrays of arrays, return types, argument types, etc
> without any ambiguity with existing syntax. The selected syntax, on the
> other hand, does have ambiguities that require special-casing many contexts,
> such as arrays.

Thanks for the comment and for the design proposal.

> Perhaps there is some motivation for the current syntax that I'm missing.

Based on your earlier comments, exactly this proposal already appears in
the "open issues" section of the JSR 308 website:
I've just updated that text slightly, and it now reads as follows:

  Consider separating type annotations from all other annotations, and put
  them in a different place in the syntax. For example, one could write
  type annotations after the type. In

	  @A Type @B var;

  @A would refer to the variable and @B would refer to the type. One
  advantage is that this makes the syntax for type annotations more uniform
  (no special cases in the grammar for return values or arrays of arrays),
  and may make the syntax less confusing, especially for arrays. One
  disadvantage is that programmers must remember which annotations are type
  annotations and which are not, which may be confusing. Another issue is
  that this proposal is not backward-compatible: it is inconsistent with
  existing annotations proposed by JSR 305, such as @NonNull.

> Well, annotations before the annotated type doesn't work, because in a
> simple variable declaration it is ambiguous with an annotation on the
> variable.

I don't think this is likely to be ambiguous:  some annotations refer to
types, and some to variables, and I expect that it will be clear to
programmers which is which.  But maybe others can come up with an example
where this would be a problem in practice.


More information about the JSR308 mailing list