如何将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])
)
答案 0 :(得分:4)
为什么不object Foo extends SomeClass with Bar with App
? App is a trait,所以它可以毫不费力地融入课堂。
答案 1 :(得分:1)
在scala中,您可以从一个类和多个特征扩展。因为App实际上是你想要的特质,你可以做一些像
这样的事情object Foo extends MyClass with App {
}