简体   繁体   English

这是Kotlin REPL的错误吗?

[英]Is this a bug of Kotlin REPL?

I can define a value in Kotlin REPL like this(recursively) without getting an error: 我可以像这样(递归地)在Kotlin REPL中定义一个值,而不会出现错误:

val s: String = s

And now I get an 's' with the type of NotNull but the value of null. 现在我得到一个'N'类型为NotNull但值为null。
And I can do something with this NotNull value with a NPE: 我可以使用NPE对此NotNull值执行某些操作:

>>> val s: String = s

>>> s.length
java.lang.NullPointerException

You can try it on your own Kotlin REPL, it works every time. 您可以在自己的Kotlin REPL上试用它,它每次都可以使用。

I am using Kotlin version 1.1.2-3. 我正在使用Kotlin版本1.1.2-3。

Yes, it is a bug of REPL. 是的,这是REPL的错误。

In the REAL Kotlin file, it will complain as a "Unresolve reference" 在REAL Kotlin文件中,它会抱怨为“Unresolve reference”

Sorry, I cannot post a img, but you could try at your IDE. 抱歉,我无法发布img,但您可以尝试使用IDE。

I am using the IntelliJ-IDEA 2017.1.3 我正在使用IntelliJ-IDEA 2017.1.3

Yes, this is a bug. 是的,这是一个错误。

val s: String = s
print(s.length)

This code compiled successfully but at runtime, it's giving an error. 这段代码编译成功,但在运行时,它给出了一个错误。

Error: Unresolved reference: s 错误:未解析的引用:s


在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM