我正在尝试使用
java9 jdk的新JShell程序.我想调试我正在制作的交互式控制台应用程序,但似乎System.in不起作用.例如:
[root@mycomputer home]# jdk-9/bin/jshell
| Welcome to JShell -- Version 9-ea
| Type /help for help
-> new Scanner(System.in).next()
它只是在这里冻结并完全锁定键盘.我必须在另一个终端中杀死进程才能得到我的提示.
正如mlk指出的那样,看起来这是known bug.有没有人找到解决方法?
My specs: Redhat x86_64, Gnome-Terminal, Java9 Build 109
最佳答案 我找到的唯一解决方法是将“输入”分配给字符串,并使用接受字符串的Scanner
constructor:
public Scanner(String source)
Constructs a new
Scanner
that produces
values scanned from the specified string.
-> String input = "Hello world"
| Added variable input of type String with initial value "Hello world"
-> Scanner sc = new Scanner(input)
| Modified variable sc of type Scanner with initial value java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\QNaN\E][infinity string=\Q∞\E]
-> sc.next()
| Expression value is: "Hello"
| assigned to temporary variable $5 of type String