Skip to content

Instantly share code, notes, and snippets.

@dchenbecker
Created May 5, 2010 18:00
Show Gist options
  • Save dchenbecker/391186 to your computer and use it in GitHub Desktop.
Save dchenbecker/391186 to your computer and use it in GitHub Desktop.
scala> trait Speaker { def speak : Unit }
defined trait Speaker
scala> val f = () => { println("Hello!") }
f: () => Unit = <function>
scala> val m = new Speaker { def speak = f() }
m: java.lang.Object with Speaker = $anon$1@3a7f1228
scala> m.getClass
res11: java.lang.Class[_] = class $anon$1
scala> val n = m.getClass.newInstance.asInstanceOf[Speaker]
n: Speaker = $anon$1@2f56f920
scala> n.speak
Hello!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment