trait =!=[A, B]
implicit def neq[A, B] : A =!= B = null
implicit def neqAmbig1[A] : A =!= A = null
implicit def neqAmbig2[A] : A =!= A = null
тогда:
scala> class A
defined class A
scala> class B[C <: A](implicit ev: C =!= A)
defined class B
scala> class D extends A
defined class D
scala> new B[D]() // OK, D is a subtype of A
res4: B[D] = [email protected]
scala> new B[A]() // Error, A =:= A
<console>:15: error: ambiguous implicit values:
both method neqAmbig1 of type [A]=> =!=[A,A]
and method neqAmbig2 of type [A]=> =!=[A,A]
match expected type =!=[A,A]
scala> class E
defined class E
scala> new B[E]() // Error, E is not a subtype of A
<console>:15: error: type arguments [E] do not conform to class B type parameter bounds [C <: A]