How to pre-initialize val and extend a class in Scala?
eg:.
object Start { def main(args: Array[String]): Unit = { new T() new T2() //T3? } } class T extends{val z = 10} with X with Y class T2 extends X with Y {val z=10} //class T3 extends{val z = 10} ??? Z with X with Y //???? class Z trait X { val z :Int } trait Y { this :X => println("Test: "+z) }
Using:
class T3 extends {val z = 10} with Z with X with Y
Scala Language Specification 2.9, 5.1.6:
EarlyDefs ::= '{' [EarlyDef {semi EarlyDef}] '}' 'with'
So for an early definition should always follow with
with
Check here for some programming examples in the scala book
Scala: usage example for early definition / early initializer / pre-initialized fields
Source: https://habr.com/ru/post/1478865/More articles:How to create a two-list generator in python? - pythonHow to localize mnemonics? - javaStrip U + 10000-U + 10FFFF from javascript strings - javascriptGrep inside multiple directories and archived files - regexWhat is the best way to encode or clean an email body when collecting emails through Ruby Net :: IMAP - ruby | fooobar.comRails: RSpec - undefined cookie_jar method for nil: NilClass - authenticationScala: An Example for Early Definition / Early Initializer / Pre-Initialized Fields - scalaOverboot issue on Twitter Bootstrap and Chrome - cssCreating a black and white checkerboard in a two-dimensional array - pythonFinding duplicate entries in a large text file - pythonAll Articles