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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -