A T
A T

Reputation: 13846

In Scala, how do I extend an object with multiple classes?

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

Answers (2)

tsachev
tsachev

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

om-nom-nom
om-nom-nom

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

Related Questions