Skip to content

Instantly share code, notes, and snippets.

@kevinwright
Created April 22, 2011 17:21
Show Gist options
  • Save kevinwright/937142 to your computer and use it in GitHub Desktop.
Save kevinwright/937142 to your computer and use it in GitHub Desktop.
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
}
@ikennaokpala
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment