问题
JShell is a Java REPL that is scheduled to be released alongside Java 9; however, there is an open beta for it.
If I create an infinite loop in JShell (Project Kulla) by typing:
-> while(true) {}
JShell will loop forever. Short of completely quitting JShell, is there a way to stop an individual line of code while it's running in JShell (after you have already begun evaluation of the code)?
回答1:
Actually there is a way. Just hit CTRL + c:
-> while(true) {}
Killed.
->
It'll kill the loop and will not exit the shell.
Note that it'll take ~1-2 seconds for the kill process to finish, if you hit it twice it'll kill the statement and then will exit the shell.
I'm using JDK 9 EA build 107 on 03-01-2016 (#4560)
来源:https://stackoverflow.com/questions/35759212/how-to-stop-infinite-loop-in-jshell-kulla