initialization - Scala: pre-initialize val while extending a class -
how pre-initialize val , extend class in scala?
e.g.:
object start { def main(args: array[string]): unit = { new t() new t2() //t3? } } class t extends{val z = 10} x y class t2 extends x y {val z=10} //class t3 extends{val z = 10} ??? z x y //???? class z trait x { val z :int } trait y { :x => println("test: "+z) }
use:
class t3 extends {val z = 10} z x y
scala language specification 2.9, 5.1.6:
earlydefs ::= ‘{’ [earlydef {semi earlydef}] ‘}’ ‘with’
so definition always has followed with
Comments
Post a Comment