vigna / fastutil

fastutil extends the Java™ Collections Framework by providing type-specific maps, sets, lists and queues.
Apache License 2.0
1.76k stars 196 forks source link

replace trailing array parameter with varargs #231

Closed nnym closed 3 years ago

nnym commented 3 years ago

Having varargs parameters instead of trailing array parameters in such list and set constructors could reduce verbosity when constructing them with a hardcoded collection of elements.

vigna commented 3 years ago

Yeah, those were created when varargs did not exist...

vigna commented 3 years ago

In any case, 8.5.0 introduces .of() factory methods that make such changes not so necessary.

vigna commented 3 years ago

In any case I converted the few constructors for sets where varargs where possible. This cover cases in which .of() is not available, such as new RBTreeSet(1, 2, 3);

vigna commented 3 years ago

Er, I had to roll back. There's a catch. For all integer types, there's a constructor with a single argument that is the size of the initial backing array. Having varargs creates a complete mess as depending on the number of arguments you get the empty set with a certain size or the set with the given elements. Let's stick to .of()...