Skip to content

Instantly share code, notes, and snippets.

@noahlz
Created August 30, 2013 04:04
Show Gist options
  • Save noahlz/6386214 to your computer and use it in GitHub Desktop.
Save noahlz/6386214 to your computer and use it in GitHub Desktop.
Understanding implicit parameter resolution provided from the companion-object scope.
package app;
object Bar {
implicit val b: Bar = new Bar(5)
}
class Bar(val x: Int) {
def doStuff() {
println(x)
}
}
object Main extends App {
def run(implicit b: Bar) :Unit = b.doStuff
run // prints 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment