Skip to content

Instantly share code, notes, and snippets.

@komamitsu
Created May 13, 2012 13:53
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 komamitsu/2688571 to your computer and use it in GitHub Desktop.
Save komamitsu/2688571 to your computer and use it in GitHub Desktop.
Trait as Stackable modifications
// Either is OK.
// abstract Base { def say(word: String) }
trait Base { def say(word: String) }
class Hoge extends Base { def say(word: String) = println(word) }
trait Smile extends Base { abstract override def say(word: String) = super.say(word + " :)") }
trait Hello extends Base { abstract override def say(word: String) = super.say("Hello " + word) }
object Hoge extends App {
val hoge = new Hoge with Smile with Hello
hoge.say("World")
}
@komamitsu
Copy link
Author

$ scalac Hoge.scala
$ scala Hoge
Hello World :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment