Skip to content

Instantly share code, notes, and snippets.

@NobukazuHanada
Created February 21, 2017 03:49
Show Gist options
  • Save NobukazuHanada/2e5aea1c0693da1242a0f6196dd5e831 to your computer and use it in GitHub Desktop.
Save NobukazuHanada/2e5aea1c0693da1242a0f6196dd5e831 to your computer and use it in GitHub Desktop.
trait Creatable[T] {
def create : T
}
object Main extends App{
implicit object CreatableInt extends Creatable[Int] {
def create : Int = 3
}
implicit object CreatableString extends Creatable[String] {
def create : String = "pa"
}
def createValue[T](implicit value: Creatable[T]) = value.create
val a = createValue[Int]
println(a)
val b = createValue[String]
println(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment