Created
April 25, 2017 14:10
-
-
Save TomLous/84392abc41d240a0498db836b171737a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
trait Parser{ | |
def parse(i: Int):String | |
} | |
implicit object ParserA extends Parser{ | |
override def parse(i: Int): String = s"A: $i" | |
} | |
// only include 1 implicit parser in case of ambiguity | |
//implicit object ParserB extends Parser{ | |
// override def parse(i: Int): String = s"B: $i" | |
//} | |
case class BaseClass(y: Int)(implicit val parser: Parser){ | |
def show = parser.parse(y) | |
} | |
val x = BaseClass(4) | |
x.show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment