【发布时间】:2017-05-11 08:04:53
【问题描述】:
我正在尝试在 Jupyter 笔记本中运行以下代码:
trait Printable extends Any {
def print(): Unit = println(this)
}
class Wrapper(val underlying: Int) extends AnyVal with Printable
object Demo {
def main(args: Array[String]) {
val w = new Wrapper(3)
w.print() // actually requires instantiating a Wrapper instance
}
}
Demo.main(Array())
执行单元格时会出现错误消息:
Name: Compile Error
Message: <console>:15: error: value class may not be a member of another class
class Wrapper(val underlying: Int) extends AnyVal with Printable
^
StackTrace:
我相信这是因为 Jupyter 可能正在运行 scala 命令而不是 scalac 命令,并且显然 scala 将所有内容包装到顶级类中以启用脚本。值类不能是内部类,因此是错误的原因。关于这个话题有一个相关的问题:
scala: how to define a value class
有没有办法解决这个问题?
我正在使用我的 Jupyter 笔记本运行 Apache Toree Scala。
操作系统:OS X 10.11.6、Scala 2.11.8、Jupyter 4.3.0、Apache Toree 0.2.0。
提前致谢!
【问题讨论】:
标签: scala jupyter-notebook jupyter apache-toree