traits - Scala: Example use for early definition / early initializer / pre-initialized fields -
scala allows make definitions so:
trait { val v: int } class b extends { val v = 4 }
what example use of feature?
whenever value used trait initialization. eaxmple trait:
trait usefultrait { val parameter : int private val myhelperobject = new myexpensiveclass(parameter) }
the parameter used substitute constructor parameter. parameter should rather made abstract method, because leaves more free space implementer.
Comments
Post a Comment