Desugaring of anonymous classes

Alex Buckley alex.buckley at
Mon Apr 1 12:59:09 PDT 2013

On 3/31/2013 11:39 AM, Michael Ernst wrote:
> In January, I removed the text from the specification that was
> compiler-specific.  This text was among the removed text:
>    As another example, an anonymous class desugars into a class declaration
>    and instantiation.  A programmer may write both type and declaration
>    annotations on an anonymous class in Java source code.  In the classfile,
>    the type annotations are copied to the class declaration and to its
>    instantiation (new expression).  The declaration annotations are copied
>    only to the class declaration.
> Do you consider this possibly implementation-specific, and therefore it
> does not belong in the specification.  Or, will every compiler follow this
> implementation strategy so it is worth re-instating as useful guidance?

It would be better to start with the concept of a class instance 
creation expression (CICE) since it lets the locations be more precise.

A CICE may create an instance of an anonymous class, in which case the 
declaration of the anonymous class is provided inline. This declaration 
is required by JLS 13.1 to compile to a form with a binary name; you can 
take this to mean a standalone class file is emitted.

A CICE may have i) type annotations in the 'new ... {' term outside the 
anonymous class declaration, and ii) type annotations and declaration 
annotations inside the anonymous class declaration. It would be 
appropriate to specify:

- The (i) annotations (type only) are stored for the CICE in its 
enclosing class file _and_ stored for the superclass of the anonymous 
class declaration in its emitted class file.

- The (ii) annotations (type and decl) are stored for the appropriate 
type uses and declarations in the class file emitted for the anonymous 
class declaration.


More information about the type-annotations-spec-experts mailing list