new keyword 'extension' really necessary?

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Aug 5 09:42:31 PDT 2010


On 05/08/10 17:33, Gernot Neppert wrote:
> Hi Maurizio,
>
> I do not have compiler writing skils, so I'm curious why the keyword 
> 'extension' should be nessesary to introduce defender methods.
> A defender method declaration without the prefix 'extension' looks 
> quite distinguishable to me. Example:
>
> interface List<E>
> {
>    void sort(Comparator<? super E> comp) default 
> Collections.sort(List<E>);
> }
>
> So, why the new keyword?
>
> (An answer such as 'This is necessary to disambiguate the grammar' 
> would suffice...)
>
>
'This is necessary to disambiguate the grammar' ;-)

Annotations:

@interface MyAnnotation {
   String stringValue() default "defaultString";
}

[I guess that with some heavy-lifting and semantic lookahead it would be 
possible for the compiler to disambiguate the two cases, however we also 
felt that 'extension' methods were peculiar enough to deserve their own 
mini-keyword]

Note that 'extension' is not a new keyword - it's a context-dependent 
keyword, which means you will still able to do:

class extension {
    extension extension = extension;
}

Maurizio


More information about the lambda-dev mailing list