RFR: JDK-8263411: Convert jshell tool to use Stream.toList()

Jan Lahoda jlahoda at openjdk.java.net
Thu Mar 18 20:27:39 UTC 2021


On Fri, 12 Mar 2021 21:51:07 GMT, Ian Graves <igraves at openjdk.org> wrote:

> This converts jshell from using `Stream.collect(Collectiors.toList())` to `Stream.toList()` - an immutable list with better performance characteristics. Local inspection only turned up one place that was mutating a resulting list and that has been refactored. 
> 
> This work is a subtask to: https://bugs.openjdk.java.net/browse/JDK-8260559

Overall looks good to me. Please see two comments inline.

src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java line 600:

> 598:                                .map(Suggestion::continuation)
> 599:                                .distinct()
> 600:                                .map(s -> (CharSequence) s)

This may be a personal preference, but I am not particularly happy about these casts (here and on other places). I'd rather:
-change the target type, if possible, so that the cast would not be necessary; in this case, changing `toShow` to `List<? extends CharSequence> toShow;` should work, and similar changes may work in other cases as well; that should make things clearer, I think. (And the `List` will be effectively unmodifiable by type, not only at runtime.)
-keep the `collect(toList())`

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

Marked as reviewed by jlahoda (Reviewer).

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


More information about the kulla-dev mailing list