Created
June 10, 2015 07:25
-
-
Save asarkar/f27d849086f77ce0136e to your computer and use it in GitHub Desktop.
Scala Mixin Demo
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 Logged { def log(msg: String) {} } | |
trait Chattery extends Logged { def chatter = log("I chatter. Do you mind?") } | |
trait ConsoleLogger extends Logged { override def log(msg: String) = println(msg) } | |
scala> val ch = new Chattery() with ConsoleLogger | |
ch: Chattery with ConsoleLogger = $anon$1@1ef7fe8e | |
scala> ch.chatter | |
I chatter. Do you mind? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment