Created
April 22, 2011 17:21
-
-
Save kevinwright/937142 to your computer and use it in GitHub Desktop.
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
trait Constructable[T] { | |
def construct: T | |
} | |
implicit object IntIsConstructable extends Constructable[Int] { | |
def construct = 42 | |
} | |
implicit object StringIsConstructable extends Constructable[String] { | |
def construct = "Hello World" | |
} | |
def testIt[T](x: T)(implicit ctor: Constructable[T]) = { | |
ctor.construct | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for this piece of learning..
def testIt[T](x: T)(implicit ctor: Constructable[T]){
println(ctor.construct +" "+ x)
}
scala> testIt[String] ("Ikenna" )
Hello World Ikenna