[JSR308] Others possible syntaxes for type annotations

Eugene Kuleshov eu at javatx.org
Wed May 16 19:40:51 EDT 2007

  I am not sure if type aliasing is either a good idea or in scope of 
the JSR 308. Though it is been considered a bad idea to add new keywords 
to Java language, including "typedef" or "syntax".

  As for alternative syntaxes, I spoke to Neal Gafter at the JavaOne 
last week and he explained his idea for non-ambiguous syntax for 
annotations to me. He was planning to send his proposal along with Java 
language grammar changes to this list.


Maxim Kizub wrote:
> Hello.
> For type annotations there may be others syntax solutions, not only 
> prefix vs postfix.
> First, annotations may be seen as "external" type parameters. This can 
> be expressed as
> Type<@NonNull> or List<String, @ConcurentAccess("write")> (or maybe 
> use ; to separate arguments and annotations)
> Next, type annotations may be shortened using typedefs, like
> typedef StringNN String<@NotNull>;
> typedef String0 String<@Nullable>;
> I tried to use typedefs (in my KievCompiler, which is used now as the 
> core language for SymADE project, http://www.symade.org),
> but found, that much more useful (for me) were postfix operators for 
> types, defined by typedefs. For instance, we can define
> typedef type? type<@Nullable>;
> typedef type! type<@NotNull>;
> typedef type# type<@Immutable>;
> and then we can use operators on any type or combine multiple postfix 
> operators together
> String? (equivalent to String<@Nullable>)
> String!# (equivalent to String<@NotNull, at Immutable>)
> The same "type operator" definition syntax can be unified and used for 
> all type parameters, for instance,
> typedef tp& WeakRef<tp>;
> will allow define weak references using & postfix type operator. Of 
> cause, since there is little ASCII operators left,
> it will be better to allow unicode operators (punctuation, 
> mathematical, arrows, technical symbols and others
> unicode subranges).
> Actually, [] and ... may be seen as "standard" type operators defined as
> typedef type[] java.lang.Array<type>;
> typedef type... java.lang.Vararg<type>;
> Also, since typedefs are expected to be common for the whole project, 
> java can have special import for syntax,
> i.e. like it has "import static ...;" we may add "import syntax ...;" 
> and record typedefs (as well as common imports for
> the project) in the named section (in KievCompiler I also use "import 
> syntax" to define operators - unicode image
> plus priority, arity and association).

More information about the JSR308 mailing list