Created
August 30, 2013 04:04
-
-
Save noahlz/6386214 to your computer and use it in GitHub Desktop.
Understanding implicit parameter resolution provided from the companion-object scope.
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
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