Please provide default impl for new methods on Collection/Map interfaces

Peter Reilly peter.kitt.reilly at gmail.com
Thu Sep 20 04:14:31 PDT 2012


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