Skip to content

Instantly share code, notes, and snippets.

@vigdorchik
Created October 24, 2013 09:08
Show Gist options
  • Save vigdorchik/7133781 to your computer and use it in GitHub Desktop.
Save vigdorchik/7133781 to your computer and use it in GitHub Desktop.
Allocationless implicits for different instantiations
class C[T]
object ImplicitString {
def foo(): Unit = Console.println("of String")
}
object ImplicitInt {
def foo(): Unit = Console.println("of Int")
}
implicit def cstrImpl(c: C[String]) = ImplicitString
implicit def cintImpl(c: C[Int]) = ImplicitInt
val cstr = new C[String]
val cint = new C[Int]
cstr.foo()
cint.foo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment