jshell中的多行粘贴

Kun*_*jia 15 java java-9 jshell

我正在尝试使用jshell,但找不到粘贴多行表达式的选项.甚至可以在jshell中粘贴多行.与scala提供的类似paste mode.

Eug*_*ene 11

所以如果你有这样的代码:

 int c = 2;
 int j = 4;
 int x = 5; 
Run Code Online (Sandbox Code Playgroud)

复制并粘贴到jshell中,只处理前两个语句.

但如果您有这样的代码:

  int c = 2; int j = 4; int x = 5;
Run Code Online (Sandbox Code Playgroud)

并粘贴到jshell:

jshell> int c = 2; int j = 4; int x = 5;
        c ==> 2
        j ==> 4
        x ==> 5 
Run Code Online (Sandbox Code Playgroud)

更多代码如下:

HashMap<Integer, Integer> map2 = new HashMap<>(); for (int i = 0; i < 15; ++i) { map2.put(i, i);map2.put(i, i); } System.out.println(map2);
Run Code Online (Sandbox Code Playgroud)

实际上会有效.

为什么?我不知道.

我知道复制/粘贴的唯一方法是通过(在jshell中输入):

/编辑

你可以随意粘贴.


Nam*_*man 10

以防万一人们仍然在这里结束,粘贴整个代码块的一个小调整jshell是用大括号将其包裹起来,{}如下所示:

{
 int c = 2;
 int j = 4;
 int x = 5; 
 // access these only in this scope though
 System.out.println("c : " + c + ", j : " + j + ", x = " + x);
}
Run Code Online (Sandbox Code Playgroud)

示例屏幕:

在此处输入图片说明


Jay*_*Jay 5

我试了一下,只处理了前两行.最后还尝试使用额外的换行符和三行以上,并且仍然只处理了前两行.我不知道为什么,但我怀疑这是一个错误.