In Scala, how do I initialize abstract vals in features?

Suppose I have the following trait with two abstract vals

trait Base { val startDate: java.util.Date val endDate: java.util.Date } 

Now I have an abstract class extending the stroke

 abstract class MyAbstract extends Base ... 

Now I want to instantiate an abstract class with several other attributes mixed in.

  def main(args: Array[String]) { new MyAbstract with MixIn1 with MixIn2 } 

How to pass specific values ​​for startDate and endDate?

+4
source share
1 answer

Since MyAbstract is an abstract class, you cannot directly create it. You need to either subclass it explicitly, or create an instance of an anonymous subclass, for example.

 def main(args: Array[String]) { val myInstance = new MyAbstract with MixIn1 with MixIn2 { val startDate = ... val endDate = ... } } 
+10
source

All Articles