Reputation: 13846
How do I inject App
into an object
already being extended by another?
object Foo extends SomeClass with Bar {
/* imports */
/* <-- Want code here to be run as if within `main` scope --> */
}
Basically I want to take advantage of the App
main class (example); without which I receive this error:
java.lang.RuntimeException: No main class detected.
(So don't need to worry about defining my own def main (args : Array[String])
)
Upvotes: 1
Views: 3214
Reputation: 1171
In scala you can extend from one class and many traits. Since App is actually a trait what you want is possible and you could do something like
object Foo extends MyClass with App {
}
Upvotes: 1
Reputation: 62855
Why not object Foo extends SomeClass with Bar with App
? App is a trait, so it could be mixed into class effortlessly.
Upvotes: 4