Skip to content

Instantly share code, notes, and snippets.

@Krasnyanskiy
Last active July 25, 2016 23:23
Show Gist options
  • Save Krasnyanskiy/61f81c4ecb9f8765fe7c5ef71f633024 to your computer and use it in GitHub Desktop.
Save Krasnyanskiy/61f81c4ecb9f8765fe7c5ef71f633024 to your computer and use it in GitHub Desktop.
-scala: context bound example
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