Reputation: 15284
I have a main base class and I want to extend it so that the main class provides basic functions to the extended class:
class Foo extends App {
println("Foo")
def bar = {}
}
class Foo2 extends Foo {
println("Foo2")
}
object Foo2 extends Foo2 {
}
But this does not work. The compile complains warning: Foo2 has a main method with parameter type Array[String], but Foo2 will not be a runnable program.
Reason: companion contains its own main method, which means no static forwarder can be generated.
How can this be achieved?
Upvotes: 1
Views: 390
Reputation: 294
There is an ambiguous name in your code. Just rename the class or object and you'll be fine
class Foo extends App {
println("Foo")
def bar = {}
}
class FooX extends Foo {
println("Foo2")
}
object Foo2 extends FooX {
}
Upvotes: 2