Kotlin的readLine函数的奇怪行为 [英] Odd behavior with kotlin's readLine function

查看:203
本文介绍了Kotlin的readLine函数的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在挑选Kotlin从事新工作,并且正在通过

I'm picking up kotlin for a new job and I'm working through the intellij hello world app for kotlin.

在演练中,您将创建一个控制台应用程序,该应用程序可读取标准输入并打印问候语:

In the walkthrough it has you create a console app that reads in standard input and prints a greeting:

fun main(args: Array<String>) {
    println("What's your name?")
    val name = readLine()
    println("Hello, $name")
}

超级简单.

我遇到的问题是,在运行该应用程序时,我也得到提示,请输入我的名字,然后输入我的名字,然后按Enter键,什么也没发生.该应用程序仍在运行,但不接受第一次按enter按钮的标准输入.

The problem I'm running into is that when running the app, I get the prompt too enter my name, I type it in, hit enter, and nothing happens. The app is still running, but it doesn't accept the standard input off of the first enter button press.

如果我再按一次Enter键一次或两次,它将最终接受输入,但会拉入一个空字符串(如果将两次按两次的enter按钮分别注册为新行,则是有意义的.)

If I press enter one or two more times it finally accepts the input but pulls in an empty string (makes sense if it registered each of the two to three enter button presses as a new line each).

无法在此处发布的屏幕截图中捕获交互,但是我确实记录了正在发生的事情的快速视频:

The interaction can't be captured in screen shots that I can post here, but I did record a quick video of what's happening: https://vimeo.com/486636891

我查找了 readLine上的kotlin文档,他们并不太了解可能发生的事情.

I looked up the kotlin docs on readLine and they don't really clue me in to what could be happening.

关于这里出了什么问题以及如何解决的任何想法?最终,我不会用kotlin编写许多控制台应用程序,所以这不是很关键,但是我的想法是无法以语言/​​工具困扰我的第一个hello-world应用程序.

Any idea of what's going wrong here and how to fix it? Ultimately I'm not going to be writing many console apps with kotlin so it's not critical, but the idea of not being able to get through the very first hello-world app in a language/tool nags at me.

嗯,在构建jar之前,它必须与源代码一起运行.

Hmm, it must be something with the running of the source code before building the jar.

如果我继续学习本教程,直到构建jar并运行它,文件运行正常:

If I continue through the tutorial to the point where I build the jar and run it the file runs fine:

令人非常沮丧的是,如果不进行构建就无法正常工作.

Still pretty frustrating that it doesn't work without building.

推荐答案

因此,在进行一番挖掘之后,似乎可能是一个IDE问题,因此我将其作为Bug提交给JetBrains.

So after digging for a bit it seemed like it may be an IDE issue, so I submitted it as a bug to JetBrains.

今天早上,我收到一封电子邮件,指出提交的邮件已被重复,标记为错误并分配给某人,因此该问题似乎是基于def IDE的,希望在不久的将来可以解决此问题.

This morning I got an email that the submission was duplicated, marked as a bug, and assigned to someone, so it looks like the issue is def IDE based and hopefully will have a fix in the near future.

这里是问题的链接,如果有人想关注进度或看到未来的结果.

Here's the link to the issue if anyone wants to follow the progress or see the future results.

这篇关于Kotlin的readLine函数的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆