Created
February 21, 2017 04:32
-
-
Save NobukazuHanada/4e3ef97ae9afeef86f8dfb3f19ccb26f 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
object Main extends App{ | |
trait Addable[T] { | |
def add(a:T) : T | |
} | |
implicit object CreatableInt extends Addable[Int]{ | |
def add(a:Int) : Int = a + 3 | |
} | |
implicit object CreatableString extends Addable[String] { | |
def add(a:String) : String = a + "pa" | |
} | |
def createValue[T](a:T)(implicit value: Addable[T]) : T = value.add(a) | |
val a = createValue(10) | |
println(a) | |
val b = createValue("hey") | |
println(b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment