Created
February 21, 2017 03:49
-
-
Save NobukazuHanada/2e5aea1c0693da1242a0f6196dd5e831 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 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