在Scala中,如何使用多个类扩展对象?

时间:2013-10-07 08:44:29

标签: scala multiple-inheritance

如何将App注入已被另一个人扩展的object

object Foo extends SomeClass with Bar {
    /* imports */
    /* <-- Want code here to be run as if within `main` scope --> */   
}

基本上我想利用App主类(example);没有它我收到这个错误:

java.lang.RuntimeException: No main class detected.

(所以不必担心定义我自己的def main (args : Array[String])

2 个答案:

答案 0 :(得分:4)

为什么不object Foo extends SomeClass with Bar with AppApp is a trait,所以它可以毫不费力地融入课堂。

答案 1 :(得分:1)

在scala中,您可以从一个类和多个特征扩展。因为App实际上是你想要的特质,你可以做一些像

这样的事情
object Foo extends MyClass with App {
}