On Thu, 4 Feb 2021 22:45:10 GMT, Ian Graves <igra...@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()`.

Aside from the simplification issues, the Collectors.toList() => 
Stream.toList() conversions look fine.

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.

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java line 579:

> 577:                     return Stream.of(Arrays.copyOfRange(args, i, 
> args.length))
> 578:                                  .toList();
> 579:                 }

As above, stream an array subrange.

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

Marked as reviewed by smarks (Reviewer).

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

Reply via email to