Created
October 24, 2013 09:08
-
-
Save vigdorchik/7133781 to your computer and use it in GitHub Desktop.
Allocationless implicits for different instantiations
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
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