I was trying out jshell and couldn't find option to paste multiple line expressions. Is it even possible to paste multiple lines in jshell. Similar to what scala offers with paste mode
.
So if you have code like this:
int c = 2;
int j = 4;
int x = 5;
Copy and paste into jshell, only the first two statements are processed.
But if you have code like this:
int c = 2; int j = 4; int x = 5;
And paste into jshell:
jshell> int c = 2; int j = 4; int x = 5;
c ==> 2
j ==> 4
x ==> 5
Even more lines of code like this:
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);
will actually work.
Why? Me don't know.
The only way I know that copy/paste will work is via (type it in jshell) :
/edit
and you can paste as much as you want.
I tried it and only the first two lines are processed. Also tried with extra newlines at the end and more than three lines, and still only the first two lines were ever processed. I don't know why but I suspect it's a bug.
This was a bug. It has been fixed: https://bugs.openjdk.java.net/browse/JDK-8169595
来源:https://stackoverflow.com/questions/41833901/multiline-paste-in-jshell