Suppose I have the following trait with two abstract vals
trait Base {
val startDate: java.util.Date
val endDate: java.util.Date
}
I now have an abstract class extending the trait
abstract class MyAbstract extends Base ...
I now wish to instantiate the abstract class with a few other traits mixed in.
def main(args: Array[String]) {
new MyAbstract with MixIn1 with MixIn2
}
How to I pass in concrete values for startDate and endDate?
Because MyAbstract
is an abstract class, you can't instantiate it directly. You need to either subclass it explicitly, or create an instance of an anonymous subclass, e.g.
def main(args: Array[String]) {
val myInstance = new MyAbstract with MixIn1 with MixIn2 {
val startDate = ...
val endDate = ...
}
}
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