IntelliJ中Scala工作表的编译问题 [英] Compilation issue of a Scala worksheet in IntelliJ
问题描述
我的工作表包含
object test {
val tableTest = new Array[String](1)
tableTest.length
}
返回
tableTest: Array[String] = [Ljava.lang.String;@628c5fdf
res0: Int = 1
似乎没问题。
但是,当我输入此工作表时:
However, when I enter this worksheet:
object test {
val tableTest = new Array[String](1)
tableTest(0) = "zero"
}
IntelliJ无法编译并返回无法从以下位置读取事件:rO0ABXNyADdvcmcuamV0YnJhaW5zLmpwcy5pbmNyZW1lbnRhbC ...
错误。
IntelliJ cannot compile and returns me a Unable to read an event from: rO0ABXNyADdvcmcuamV0YnJhaW5zLmpwcy5pbmNyZW1lbnRhbC...
error.
我做错了什么?
推荐答案
我对最新的Idea和Scala插件有同样的问题。
似乎工作表在执行任何求值为Unit的行时出现问题。分配是单位,这就是你的 tableTest(0)=零
失败的原因。
I'm having the same issue with latest Idea and Scala plugin.
It seems that the worksheet has a problem executing any line which evaluates to Unit. Assigning is Unit, that's why your tableTest(0) = "zero"
fails.
我暂时通过以下解决方法解决了这个问题:
I've temporarily solved it with the following workaround:
此行将失败,错误错误:无法从以下位置读取事件:...
println("Will fail")
您可以通过定义此辅助方法并将其用于任何单位表达式来修复它: / p>
You can fix it by defining this helper method and using it for any Unit expression:
def unit(f: => Unit): String = {f; ""}
unit(println("Will work"))
你只需要忽略它在输出面板中使用生成的行res0:String =
您也可以将此方法放在某个对象中并导入所需的任何WS。
You just have to ignore the line it generates in the output panel with res0: String =
You also can put this method in some object and import in any WS you need.
加斯顿。
@ktonga
Gaston.
@ktonga
这篇关于IntelliJ中Scala工作表的编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!