On Fri, 5 Feb 2021 17:11:24 GMT, Stuart Marks <sma...@openjdk.org> wrote:

>> A subtask [JDK-8260559](https://bugs.openjdk.java.net/browse/JDK-8260559). 
>> This is an enhancement to update jlink's usage of `Collections.toList()` to 
>> `Stream.toList()`.
>
> src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java line 569:
> 
>> 567:                                         ? 
>> Stream.of(Arrays.copyOfRange(args, i, args.length))
>> 568:                                                 .toList()
>> 569:                                         : Collections.emptyList();
> 
> This is probably out of scope for a simple toList() conversion, but there are 
> some additional ways this code could be simplified. It's possible to stream a 
> subrange of an array directly:
> 
> `Arrays.stream(args, i, args.length).toList()`
> 
> Since a zero-length array subrange results in a valid zero-length list, the 
> enclosing ternary is unnecessary:
> 
> `return Arrays.stream(args, ++i, args.length).toList();`
> 
> It's also possible to do this without using streams at all,
> 
> `return List.copyOf(Arrays.asList(args).subList(++i, args.length));`
> 
> but this actually seems more cumbersome than streaming the array subrange. In 
> any case, perhaps this sort of cleanup could be reserved for a future 
> changeset from the jlink maintainer.

Agree that it's less cumbersome, but will keep it for a future clean up.

-------------

PR: https://git.openjdk.java.net/jdk/pull/2416

Reply via email to