gpt4 book ai didi

java - 寻找 JShell 输入解决方法

转载 作者:搜寻专家 更新时间:2023-11-01 03:19:15 27 4
gpt4 key购买 nike

我正在使用 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 

最佳答案

我发现的唯一解决方法是将“输入”分配给一个字符串,并使用Scannerconstructor接受一个字符串:

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

关于java - 寻找 JShell 输入解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36013456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com