Created
August 26, 2011 14:55
-
-
Save kmizu/1173588 to your computer and use it in GitHub Desktop.
REPL version sample code inspired by http://www.ne.jp/asahi/hishidama/home/tech/scala/trait.html#h_source_split
This file contains hidden or 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
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> trait scope { | |
| class A extends AnyRef with Z { | |
| def aaa() = zzz2() | |
| def aaa2() = 100 | |
| } | |
| trait Z {self: A => | |
| def zzz() = aaa2() | |
| def zzz2() = 22 | |
| } | |
| } | |
defined trait scope | |
scala> object M extends scope { | |
| def main(args: Array[String]) { | |
| val a = new A | |
| println(a.aaa() + a.zzz()) | |
| } | |
| } | |
defined module M | |
scala> M.main(Array()) | |
122 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment