Last active
November 4, 2015 09:23
-
-
Save vidma/ad6735fffdbdf89a8f1d 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 T { | |
val v = 3 | |
// if v is overriden, and this is val, this yields not what you'd expect | |
// lazy val or def would work ok. | |
val version = v | |
} | |
class C extends T { | |
override val v = 2 | |
} | |
(new C).version | |
// get unexpected: Map(3 -> 3, 2 -> 2) | |
// version two | |
trait T { | |
var metricsData: Map[Int, Int] = Map() | |
// missing lazy here | |
val v = add(3) | |
def add(v: Int) = { metricsData += v -> v; v } | |
val version = v | |
} | |
class C extends T { | |
override val v = add(2) | |
} | |
(new C).metricsData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment