Skip to content

Instantly share code, notes, and snippets.

@eiennohito
Created November 3, 2015 12:44
Show Gist options
  • Save eiennohito/b82d5954a0acdf49cbad to your computer and use it in GitHub Desktop.
Save eiennohito/b82d5954a0acdf49cbad to your computer and use it in GitHub Desktop.
int 1,2,3
long 1,2,3
Process finished with exit code 0
trait A[T] {
def name: String
}
object A {
implicit object Aint extends A[Int] { def name = "int" }
implicit object Along extends A[Long] { def name = "long" }
}
class C {
def x[T: A](ts: Seq[T]) = println(s"${implicitly[A[T]].name} ${ts.mkString(",")}")
}
object D {
def main(args: Array[String]): Unit = {
val c = new C
c.x(List(1, 2, 3))
c.x(List(1L, 2L, 3L))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment