RFR: 8309235: Unnamed Variables (_) can't be used in JShell [v2]

Andrey Turbanov aturbanov at openjdk.org
Tue Jun 6 15:45:58 UTC 2023


On Tue, 6 Jun 2023 15:33:14 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:

>> This PR addresses the issue of JShell not accepting unnamed local variables. This solution prints all local variables via the `/vars` command. e.g.,
>> 
>> 
>> jshell> int _ = 42;
>>  ==> 42
>> 
>> jshell> int _ = 43;
>>  ==> 43
>> 
>> jshell> String _ = "44";
>>  ==> "44"
>> 
>> jshell> /vars
>> |    int _ = 42
>> |    int _ = 43
>> |    String _ = "44"
>
> Aggelos Biboudis has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix NPE

src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java line 3354:

> 3352:                     : getResourceString("jshell.msg.vars.not.active");
> 3353:             String varName = vk.name();
> 3354:             hard("  %s %s = %s", vk.typeName(),  varName.isEmpty() ? "_" : varName, val);

Suggestion:

            hard("  %s %s = %s", vk.typeName(), varName.isEmpty() ? "_" : varName, val);

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14337#discussion_r1219887603


More information about the kulla-dev mailing list