Return types array/list/stream [was: API question for point lambdafication]

Zhong Yu zhong.j.yu at
Wed Feb 20 09:58:56 PST 2013

On Wed, Feb 20, 2013 at 11:22 AM, Stephen Colebourne
<scolebourne at> wrote:
> On 20 February 2013 16:54, Patrick Wright <pdoubleya at> wrote:
>>> think, like all new features, there is a danger of over-use. Laying
>>> down some guidelines on usage is a Good Thing IMO. Stream really
>>> shouldn't be the default return type - List is frequently much more
>>> useful to clients.
>> For the record, can you tell us exactly why (perhaps with code examples) you
>> feel that "list is...more useful to clients?"
> Asides from having a working toString, hashCode, equals, it has many
> other methods that allow practical manipulation by developers, such as
> indexOf, lastIndexOf, contains or subList. It can also be passed on to
> other methods (which you may not have written) that expect a list.
> While all of these things can be achieved using an array, they are
> frequently a pain to read.
> I don't recall writing code returning an array publicly in a long
> time. If I reviewed any code from someone doing it I'd want a very
> good justification for using an array.

Array was a poor man's generics, since Java had String[] but not
List<String>. That's why array was a better return type than List.
After generics, non-primitive arrays should be avoided, in all places,
unless there's a solid performance concern.

Zhong Yu

More information about the lambda-dev mailing list