Please provide default impl for new methods on Collection/Map interfaces
Aleksey Shipilev
aleksey.shipilev at oracle.com
Thu Sep 20 04:43:58 PDT 2012
I think it is correct to have compile-time error with target=1.6; since
there you might then get these classes to run in JDK6, and get linkage
error at runtime. Maurizio should know better.
-Aleksey.
On 09/20/2012 03:37 PM, Peter Reilly wrote:
> Looking at the code, I see that there are indeed default implementations for
> these methods.
>
> Looking at my build, I see that I was compiling with target=1.6 source=1.6.
> When I set these to 1.8, the problem goes away.
>
> The code should still compile with target=1.6,source=1.6, however I can see
> that handling of the default methods in this case may be problematic.
>
> Thanks for the very quick response!
>
> Peter
>
>
> On Thu, Sep 20, 2012 at 12:17 PM, Aleksey Shipilev
> <aleksey.shipilev at oracle.com> wrote:
>> Well, I'm puzzled at this point. If your classes are extending
>> AbstractCollection, they implicitly extend Collection, and Collection
>> has default methods to be picked up.
>>
>> Are you compiling with lambda/lambda javac? Vanilla JDK8 javac would not
>> work, since it does not know anything about default methods yet.
>>
>> -Aleksey.
>>
>> On 09/20/2012 03:14 PM, Peter Reilly wrote:
>>> No problem.
>>>
>>> My code extends AbstractCollection and AbstractMap.
>>>
>>> The changes I made to them are:
>>> - i.e. implement Collection.stream, Colleciton.addAll(Stream) and
>>> similar methods in Map.
>>>
>>> Peter
>>>
>>> ----------------------------------------
>>> preilly at mint-Precision-M6400
>>> ~/Public/hg/lambda/jdk/src/share/classes/java/util $ hg diff .
>>> diff -r ee96d823b92c src/share/classes/java/util/AbstractCollection.java
>>> --- a/src/share/classes/java/util/AbstractCollection.java Fri
>>> Sep 14 16:46:42 2012 -0700
>>> +++ b/src/share/classes/java/util/AbstractCollection.java Thu
>>> Sep 20 12:09:48 2012 +0100
>>> @@ -25,6 +25,8 @@
>>>
>>> package java.util;
>>>
>>> +import java.util.streams.*;
>>> +
>>> /**
>>> * This class provides a skeletal implementation of the <tt>Collection</tt>
>>> * interface, to minimize the effort required to implement this interface. <p>
>>> @@ -75,6 +77,10 @@
>>> */
>>> public abstract Iterator<E> iterator();
>>>
>>> + public Stream<E> stream() {
>>> + return null;
>>> + }
>>> +
>>> public abstract int size();
>>>
>>> /**
>>> @@ -345,7 +351,9 @@
>>> modified = true;
>>> return modified;
>>> }
>>> -
>>> + public void addAll(Stream<? extends E> c) {
>>> +// return false;
>>> + }
>>> /**
>>> * {@inheritDoc}
>>> *
>>> diff -r ee96d823b92c src/share/classes/java/util/AbstractMap.java
>>> --- a/src/share/classes/java/util/AbstractMap.java Fri Sep 14
>>> 16:46:42 2012 -0700
>>> +++ b/src/share/classes/java/util/AbstractMap.java Thu Sep 20
>>> 12:09:48 2012 +0100
>>> @@ -25,6 +25,8 @@
>>>
>>> package java.util;
>>> import java.util.Map.Entry;
>>> +import java.util.streams.*;
>>> +import java.util.functions.BiBlock;
>>>
>>> /**
>>> * This class provides a skeletal implementation of the <tt>Map</tt>
>>> @@ -66,6 +68,10 @@
>>> */
>>>
>>> public abstract class AbstractMap<K,V> implements Map<K,V> {
>>> + public MapIterator<K,V> iterator() { return null; }
>>> + public MapStream<K,V> stream() { return null; }
>>> + public void forEach(BiBlock<? super K, ? super V> block) {}
>>> + public void addAll(MapStream<? extends K, ? extends V> stream) {}
>>> /**
>>> * Sole constructor. (For invocation by subclass constructors, typically
>>> * implicit.)
>>>
>>>
>>> On Thu, Sep 20, 2012 at 11:31 AM, Aleksey Shipilev
>>> <aleksey.shipilev at oracle.com> wrote:
>>>> Hi Peter,
>>>>
>>>> On 09/20/2012 01:37 PM, Peter Reilly wrote:
>>>>> However, while attempting to compile some current code with the jdk8 compiler,
>>>>> there were a small number of issues with code that implements some java.util
>>>>> interfaces. The two that my code had problems with were Collection and Map.
>>>>
>>>> Can you provide a more concrete example? Was that your custom
>>>> collections were failing to compile against JDK8?
>>>>
>>>>> I worked around this by compiling a custom version of lamdba with the
>>>>> missing methods getting default implementation in
>>>>> j.u.AbstractCollection and j.u.AbstractMap.
>>>>
>>>> Aha, so your collections were implementing Collection, but not extending
>>>> AbstractCollection? Which methods you had to add? I see most of the new
>>>> methods have defaults in Collection.
>>>>
>>>> -Aleksey.
>>>>
>>>>
>>>>
>>
More information about the lambda-dev
mailing list