由於是一個廣義類型約束強制執行階=:=
平等,是有一個強制執行「不等於」對於類型?基本上!=
但類型?
編輯
評論下方指向現有Q&A,答案似乎是:(1)不,它不是在標準庫(2)是的,這是可能的定義之一。
所以我會修改我的問題,因爲我看到答案後發生在我身上的一個想法。
鑑於現有的解決方案:
sealed class =!=[A,B]
trait LowerPriorityImplicits {
implicit def equal[A]: =!=[A, A] = sys.error("should not be called")
}
object =!= extends LowerPriorityImplicits {
implicit def nequal[A,B](implicit same: A =:= B = null): =!=[A,B] =
if (same != null) sys.error("should not be called explicitly with same type")
else new =!=[A,B]
}
case class Foo[A,B](a: A, b: B)(implicit e: A =!= B)
如果A <: B
或A >: B
,將它仍然是這樣的情況A =!= B
?如果沒有,是否有可能修改解決方案,如果A =!= B
那麼它不是A <: B
或A >: B
?
SO開發者應該*確實*修正他們的搜索錯誤,以便尋找'=!='實際上列出了這個問題。這個bug現在已經有4年了。 –