1

Since the method

Stream.of(T... values)

includes the case of a single element, why is the method:

Stream.of(T t)

also included in the API? What's its purpose? When is it invoked? Does it do anything different from the varargs version?

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
kousen
  • 2,897
  • 3
  • 28
  • 26
  • For the same reason as http://stackoverflow.com/questions/31924249/why-does-enumset-have-many-overloaded-of-methods – Tunaki Aug 16 '16 at 07:55

1 Answers1

7

What's its purpose?

A small improvement in efficiency for a common use case.

When is it invoked?

When you have one argument.

Does it do anything different from the varargs version?

The out come is the same, but it creates less garbage.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130