Skip to content

Instantly share code, notes, and snippets.

@NobukazuHanada
Created February 21, 2017 04:32
Show Gist options
  • Save NobukazuHanada/4e3ef97ae9afeef86f8dfb3f19ccb26f to your computer and use it in GitHub Desktop.
Save NobukazuHanada/4e3ef97ae9afeef86f8dfb3f19ccb26f to your computer and use it in GitHub Desktop.
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