Sized

Brian Goetz brian.goetz at oracle.com
Fri Nov 2 15:05:33 PDT 2012


We've been using a placeholder interface Sized in the Streams API, for 
two reasons:
  - It is useful to indicate that an aggregate knows its size 
(Collections do, but not all Iterables do, and we've taken advantage of 
this in the Streams library)
  - It provides a piece of the story for the migration to 64-bit 
collections.

Here's how this migration story might work.  Today, we have:

interface Sized {
     int size();
     default long longSize() { return size(); }
}

and add it as a new supertype of Collection.

Then (now or later) we can add a subtype:

interface LongSized extends Sized {
     default int size() {
         long size = longSize();
         if (size > Integer.MAX_VALUE)
              throw something;
         return (int) size;
     }

     long longSize(); // reabstraction
}

Then, 64-bit-aware collections can implement LongSized.



More information about the lambda-libs-spec-observers mailing list