Created
October 24, 2013 10:50
-
-
Save vigdorchik/7135016 to your computer and use it in GitHub Desktop.
Use AnyVal
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 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