Last active
August 29, 2015 14:03
-
-
Save igstan/238455b45336433d3d0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait A { | |
val count: Int | |
val elements: Array[String] = new Array(count) | |
} | |
class C extends A { | |
override val count = 10 | |
} | |
val c = new C | |
println(c.elements.length) // Surprise, it's 0. | |
// ----------------------------------------------------------------------------- | |
// Using an early definition. | |
// ----------------------------------------------------------------------------- | |
trait A { | |
val count: Int | |
val elements: Array[String] = new Array(count) | |
} | |
class C extends { // early definition | |
override val count = 10 | |
} with A | |
val c = new C | |
println(c.elements.length) // 10 |
Author
igstan
commented
Jun 30, 2014
- http://www.scala-lang.org/files/archive/spec/2.11/05-classes-and-objects.html#early-definitions
- http://stackoverflow.com/q/16348541/58808
- http://stackoverflow.com/q/4712468/58808
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment