Last active
July 25, 2016 23:23
-
-
Save Krasnyanskiy/61f81c4ecb9f8765fe7c5ef71f633024 to your computer and use it in GitHub Desktop.
-scala: context bound example
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
object ContextBoundExample { | |
def main(args: Array[String]) { | |
class Identity[T] { | |
def identity(t: T) = t | |
} | |
implicit val int_id = new Identity[Int] | |
implicit val str_id = new Identity[String] | |
def bar[T: Identity](t: T) = implicitly[Identity[T]].identity(t) | |
println(bar(5)) | |
println(bar("abc")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment