Note on java.util.functions

David Conrad drconrad at gmail.com
Tue May 22 03:09:52 PDT 2012


I'm looking through java.util.functions.* and trying it out, and noticed a
few things.

Iterables.getFirst() and Iterators.getFirst() should throw
NoSuchElementException if there are no elements, not return null, which is
a perfectly valid element in some collections. Also, they should just be
named first(), IMHO.

The Blocks.chain() overloads that take lists or arrays of blocks claim to
make defensive copies, but do not.

In some of the javadoc, particularly in Blocks and Mappers, the contraction
"who's" is used where possessive "whose" is wanted. Also, the wrong "its"
appears. Examples:

"Return a Block who's apply method does nothing.", "A mapper which who's
map method returns the provided input.", "A mapper which performs a mapping
from an object to it's string representation."

The javadoc is garbled in the overload of Block.chain() that takes a first
block and an array of blocks.

The javadoc for Block's ctor says "singleton utility class", but it's not a
singleton, it's a -- I don't know what you'd call it -- a nulliton? A
zero-ton? :) Mappers is also not instatiable, but calls itself a singleton.

Several static utility classes throw AssertionError in the ctor, but
Iterables, Iterators, and ParallelIterables just throw Error. I think
AssertionError should be preferred; that's what java.util.Objects uses.

I know it's early days for this package, but I thought I'd mention it
anyway. This is all based on the April 12 lambda build
1.8.0-ea-lambda-nightly-h140-20120412-b35-b00.

Cheers,
David

P.S. Love throwing an AssertionError from the ctor. I hadn't thought of
that before but I'm going to do that in all my static utility classes from
now on.


More information about the lambda-dev mailing list