default methods in interfaces
Paul Sandoz
paul.sandoz at oracle.com
Tue Oct 29 12:49:38 PDT 2013
On Oct 29, 2013, at 8:27 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
> On Tue, Oct 29, 2013 at 4:05 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>> Hi Mohan,
>>
>> The primary use-case for default methods is to evolve interfaces without breaking compatibility [*]. Without such a mechanism we would not have been able to evolve the Collections API and integrate it with the Streams API.
>>
>> See section 10 of:
>>
>> http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-final.html
>>
>> What you are asking may have been discussed before, search here:
>>
>> http://openjdk.markmail.org/search/?q=lambda-dev
>>
>> Default methods can be used as a limited form of traits to mix-in behaviour but not state, so they ain't like Scala's traits. Any state (or context) needs to be passed as parameters to those methods. Also note that because there is no state then there are no state-realted issues associated multiple
>
> Usually an interface with default methods is stateful, e.g. List;
IMHO that is a rather misleading way of stating things (pun intended). I think it important to differentiate between the interface and implementations of, otherwise it's just gonna confuse people.
Paul.
More information about the lambda-dev
mailing list