I know a trait can extend a class which has an empty parameter constructor:
class Foo
trait Bar extends Foo
but is it possible to extend a class which constructor has some parameters?
class Foo(b: Boolean)
trait Bar extends Foo(true)
Is it possible to achieve this? It seems it's not possible. but why?
Thanks
Yes, it's possible, you just can't give constructor arguments:
trait Bar extends Foo { ... }
But to instantiate it you need to call the constructor as well:
new Foo(false) with Bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With