Am 13.07.19 um 06:29 schrieb 'David Beaumont' via guava-discuss:
> I suspect this might be unavoidable when using the "extended varargs"
> pattern.
>
> The signature of any method like:
> foo(T e1, ..., T eN, T... remaining)
>
> Is ambiguous if there is only one "remaining" element and T is itself an
> array.
In particular if it's an array U[] where U is T or a supertype.
There are rules for this situation, and the caller can use a type cast
to select whether the U[] should be treated as a single parameter or as
varargs, but nobody cares to remember them (I certainly don't).
Since this is a source of subtle bugs, I for myself have come to the
conclusion that overloading foo(T... varargs) with foo(T e1, T... es)
etc. is an API misdesign.
I found foo(List<T>) to be an acceptable substitute:
foo(Arrays.asList(t1, t2, t3, ...)) clearly expresses the intent at the
caller side, and if that pattern comes up often enough in real-world
code, JIT makers should start optimizing it away (if they haven't done
so already).
Things *still* can go wrong if T itself is List or a superclass.
I avoid varargs in that case.
Just my 2c of API design tinkering results; YMMV.
Regards,
Jo