Created
December 10, 2009 21:17
-
-
Save retronym/253684 to your computer and use it in GitHub Desktop.
Limitations of Early Definitions, a new feature in Scala 2.8
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 Base { | |
val abstractVal: String | |
final val useAbstractVal = abstractVal | |
} | |
{ | |
class C1 extends Base { | |
val abstractVal = "C1.abstractVal" | |
} | |
assert(new C1().useAbstractVal eq null) | |
} | |
{ | |
class C2 extends { | |
val abstractVal = "C2.abstractVal" | |
} with Base | |
assert(new C2().useAbstractVal == "C2.abstractVal") | |
} | |
{ | |
trait T1 extends { | |
val abstractVal = "T1.abstractVal" | |
} with Base | |
class C3 extends T1 | |
assert(new C3().useAbstractVal eq null) // why not == "T1.abstractVal" ? | |
} | |
{ | |
class T2 extends { | |
val abstractVal = "T2.abstractVal" | |
} with Base | |
case object O1 extends T2 | |
assert(O1.useAbstractVal == "T2.abstractVal") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment