fork download
  1. object Main extends App {
  2.  
  3. trait Foo[T] { def doStuff(t : T) : Unit }
  4. object Foo { def doStuff[T : Foo](t : T) = implicitly[Foo[T]].doStuff(t) }
  5.  
  6. implicit object IntFoo extends Foo[Int] { def doStuff(x : Int) = println(x * 10) }
  7. implicit object StringFoo extends Foo[String] { def doStuff(s : String) = println(s"Incoming string: $s") }
  8.  
  9. Foo.doStuff(10)
  10. Foo.doStuff("test")
  11.  
  12. }
Success #stdin #stdout 0.36s 322176KB
stdin
Standard input is empty
stdout
100
Incoming string: test