Default method survey results

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Aug 13 07:24:34 PDT 2012


On 13/08/12 15:09, Jose A. Illescas wrote:
> Gregg,
>
>     Compiler can add "default" keyword for every method (on interface)
> with implementation (delimiteded with "{...}" instead of "default")
>
>     Demarcations on developer hands are ugly, (I think) must be resolved
> by compiler...
In the Java land we tend to adhere to the general principle of 'reading 
is more important than writing' - can the 'default' keyword be omitted 
in principle? Yes, it is indeed trivial to do so in the compiler. Do we 
really want to go down that path? I don't think so, for the following 
reasons:

*) a keyword (like default) at the beginning of the method declaration 
will make it very clear and unambiguous that the following method 
declaration is kinda special. Of course you could 'infer' the same 
information by looking as to whether the method has a body or not, but 
it's also a matter of clarity (think of cases where you have multiple 
thrown types, annotations, etc.).

*) Proposals for alternate ways of specifying default method 
implementations (i.e. other than specifying a method block) have been on 
the table for quite some time; i.e. use a method reference to denote the 
default implementation. Or some syntactic shorthand in case the only 
thing you need to do is to disambiguate between two superinterface 
members using a qualified super call. If such proposals will ever be 
part of the language, it will be increasingly difficult for the human 
reader to immediately grasp as to whether a method is a default method 
or not, as the proposed 'has a block?' rule of thumb would no longer hold.

Maurizio
>
>
> On 13/08/2012 15:52, Gregg Wonderly wrote:
>> In this day and age of the Java language, reusing existing keywords,
>> trying to shoehorn them into use for a new purpose, can feel a little
>> clumsy.  Annotations can provide a much better mechanism in many
>> cases, simply because the right nomenclature is helpful.
>>
>> However, annotations also have a very specific usage scenario with
>> tooling and moment-of-use issues.  For me, this means that you can't
>> use annotations in places that annotations wouldn't work with the
>> normal annotation tooling.  You certainly don't want to have to have a
>> special class of annotation that further confuses the use of
>> annotations in other cases.
>>
>> The use of "default" isn't awesome, but it does provide a usable
>> demarcation which the compiler and run-time class loading can use to
>> make the right decision for how to build the v-tables to dispatch the
>> default method should it be involved some how.
>>
>> Gregg Wonderly
>>
>> On 8/13/2012 8:35 AM, Jose A. Illescas wrote:
>>> On 13/08/2012 15:23, Deepak S Patwardhan wrote:
>>>>> -----Original Message-----
>>>>> From: lambda-dev-bounces at openjdk.java.net [mailto:lambda-dev-
>>>>> bounces at openjdk.java.net] On Behalf Of Jose A. Illescas
>>>>> Sent: 13 August 2012 16:40
>>>>> To: Brian Goetz
>>>>> Cc: lambda-dev at openjdk.java.net
>>>>> Subject: Re: Default method survey results
>>>>>
>>>>> Brian, Why not add one thirth option (without "default" keyword) to
>>>>> poll?
>>>>>
>>>>> 1.  void foo() default {
>>>>>              System.out.println("foo");
>>>>>          }
>>>>>
>>>>> 2.  default void foo() {
>>>>>              System.out.println("foo");
>>>>>          }
>>>>>
>>>>> 3.     void foo() {
>>>>>
>>>>>              System.out.println("foo");
>>>>>          }
>>>>>
>>>> If we explore going down this path, I think we should also explore
>>>> using an
>>>> annotation,
>>>>
>>>> @java.lang.Default
>>>> void foo() {
>>>>        System.out.println("foo");
>>>> }
>>>>
>>> Deepak, why proposed annotation?
>>>
>>>        I would like see an implementation as any other java method
>>> (without new keywords, annotations, ...)
>>>
>>>        Implements a interface method ("default") must be equals to
>>> implement another class method (I want "complexity" out of developer
>>> hands, into compiler...)
>>>
>>>
>>>
>>>> I would be interested in knowing if using such an annotation has any
>>>> demerits.
>>>>
>>>> Regards,
>>>> Deepak S Patwardhan.
>>>>
>>>>> On 12/08/2012 00:30, Brian Goetz wrote:
>>>>>> Poll is closed, and results can be seen here:
>>>>>>
>>>>>>
>>>>>>
>>>>> https://www.surveymonkey.com/sr.aspx?sm=xPw4AxfWK2TTQLQtbIpQCg0l
>>>>> bkw_2fuYDiZnrBDB_2bPyd4_3d
>>>
>>
>



More information about the lambda-dev mailing list