原文链接 http://stackoverflow.com/questions/16348541/scala-example-use-for-early-definition-early-initializer-pre-initialized-fi#
Let's see a example from the Programming in Scala book (page 451). If we have a definition like this:
Then numerArg and denomArg are called abstract vals & the trait can be used directly without extends, like this:
Or
The above two are both valid Pre-initializing of abstract val in trait, except that when you need to put an expression value to abstract vals, you can only use the later form, like this:
Another interesting example in book is to Pre-initialized fields in a class definition.
|