相关疑难解决方法(0)

Scala中类型不相等的证据

有没有办法约束一个方法,只有两种类型被证明相等才有意义?

trait Something[A, B] {
  // I can only be called if type A is the same as type B
  def ifEqual(implicit ev: A =:= B)

  // Now I cannot be called if type A is proven to be the same as type B
  def ifNotEqual(implicit ev: A ??? B)
}
Run Code Online (Sandbox Code Playgroud)

types scala implicits shapeless

4
推荐指数
1
解决办法
1015
查看次数

标签 统计

implicits ×1

scala ×1

shapeless ×1

types ×1