new keyword 'extension' really necessary?

Rémi Forax forax at univ-mlv.fr
Thu Aug 5 12:17:58 PDT 2010


Le 05/08/2010 20:25, Osvaldo Doederlein a écrit :
> Extension methods are not allowed inside annotations, so I guess the
> implementation and spec issues are at least less severe, as
> disambiguation is trivial by the outer context being an annotation or
> not. Maybe it can't be completely handled by (simple) grammar changes,
> but that would be about it (it seems; correct me if that's wrong).
>    

In fact, there is no 'grammar' problem.
The local keyword 'extension' avoid to change too much the javac parser,
a hand written top-down recursive parser.

But the real value is, as Brian says, that an extension method
is tagged with the local keyword 'extension'.
Easy to explain, easy to grasp.

> And I think the similar style (same syntax for annotation defaults and
> for extension methods) is actually good. These are basically the same
> thing, in a very abstract level: a structure (interface or annotation)
> that has some feature (annotation field or method) which offers a
> default "value".
>
>    

Rémi

> 2010/8/5 Brian Goetz<brian.goetz at oracle.com>:
>    
>> In addition to Maurizio's syntactic arguments, we believe there is value in
>> identifying extension methods as, well, extension methods.
>>      
> By the same logic, maybe we need an army of new redundant qualifiers
> such as "method", "field", etc.?
>
> (OTOH, we already have some redundant qualifiers - like 'abstract' for
> a method signature that's not followed by '{', or allowing 'private
> final' methods and 'public' interface methods, or 'final' for
> arguments in abstract method declarations. But I don't want more of
> the same.)
>
> A+
> Osvaldo
>
>    
>> On 8/5/2010 12:33 PM, 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...)
>>>
>>>
>>>
>>>        
>>
>>      
>    



More information about the lambda-dev mailing list