Skip to content

Instantly share code, notes, and snippets.

@ohsitab
Created May 25, 2010 21:23
Show Gist options
  • Save ohsitab/413710 to your computer and use it in GitHub Desktop.
Save ohsitab/413710 to your computer and use it in GitHub Desktop.
class A
class B extends A
class C
class D
implicit def d2a(d: D) = new A
val (a, b, c, d) = (new A, new B, new C, new D)
//def u[T <: A](x: T): A = x
def u[T](x: T)(implicit f: T <:< A): A = x
u(b) // ok
u(d) // error
// a, b => ok, c, d => error
def e[T](x: T)(implicit f: T =:= A): A = x
// a => ok, b, c, d => error
// def v[T <% A](x: T): A = x
// def v[T](x: T)(implicit f: T => A): A = x
def v[T](x: T)(implicit f: T <%< A): A = x
// a, b, d => ok, c => error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment