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

Ian Graves igraves at openjdk.java.net
Thu Mar 18 22:25:52 UTC 2021


On Thu, 18 Mar 2021 20:41:16 GMT, Rémi Forax <github.com+828220+forax at openjdk.org> wrote:

>> 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())`
>
>>  that should make things clearer, I think. (And the `List` will be effectively unmodifiable by type, not only at runtime.)
> 
> Jan,
> don't forget that you can always do a `add(null)` or `clear()` on a List<? extends CharSequence>, so there is no way in Java to specify an unmodifiable type for a java.util.List.

Updated to match the suggestions RE the `toShow` assignments.

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

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


More information about the kulla-dev mailing list