Question regarding interface java.util.Sized

Gernot Neppert mcnepp02 at
Fri Oct 26 04:54:16 PDT 2012

Hello all,

while browsing the latest lambda-related sourcecode, I came across the
new mixin-style interface "java.util.Sized".

The JavaDoc says:
"Implementing this interface allows an object to indicate that its
elements may be efficiently counted."

OK, so what do we do with this interface? In what contexts do we want
to test for "instanceof Sized" and then query its size()?
As far as I can see, "Sized" is implemented by:


I think that interfaces should have both of the following properties:
1. Provide uniform access to an aspect of a class.
2. Provide a common handle to a polymorphic set of instances that can
reasonably put to use

IMHO, "Sized" fails to have property 2.)

It is hard to see what usecase would want to handle a polymporphic set
of Collections, Maps and Node, let alone handle them as "Sized"
objects, where the only operation you could invoke would be size().
This, java.util.Collection and java.util.Map gain nothing from
implementing "Sized"
If there are cases where it is useful to discriminate between sized an
non-sized flavours of a specific class or interface, it makes more
sense to provide an interface that extends that baseclass or

interface SizedStream extends Stream {
  public int size();

Just my 2 cents...

More information about the lambda-dev mailing list