Skip to content

Instantly share code, notes, and snippets.

@vigdorchik
Created October 24, 2013 10:50
Show Gist options
  • Save vigdorchik/7135016 to your computer and use it in GitHub Desktop.
Save vigdorchik/7135016 to your computer and use it in GitHub Desktop.
Use AnyVal
class ImplicitString(val c : C[String]) extends AnyVal {
def foo(): Unit = Console.println(c.t.toUpperCase())
}
class ImplicitInt(val c: C[Int]) extends AnyVal {
def foo(): Unit = Console.println(c.t)
}
object Main {
implicit def cstrImpl(c: C[String]) = new ImplicitString(c)
implicit def cintImpl(c: C[Int]) = new ImplicitInt(c)
def main(args: Array[String]) {
val cstr = new C[String]("hw")
val cint = new C[Int](0)
cstr.foo()
cint.foo()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment