Skip to content

Instantly share code, notes, and snippets.

@asarkar
Created June 10, 2015 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asarkar/f27d849086f77ce0136e to your computer and use it in GitHub Desktop.
Save asarkar/f27d849086f77ce0136e to your computer and use it in GitHub Desktop.
Scala Mixin Demo
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