繁体   English   中英

在Scala中定义自定义Ordered类型时出现不清楚的错误

[英]Unclear error when defining a custom Ordered type in Scala

implicit class OrderableFoo[T<:Foo[A,_] forSome {type A <: Ordered[A]}](thisFoo:Foo)
extends Ordered[Foo]{
override def compare(other:Foo):Int = thisFoo.value.compare(other.value)
}

我的问题:

thisFoo.value返回类型A的值

A型订购

thisFoo.value.compare需要一个类型为A的参数

other.value是类型A

thisFoo.value.compare(other.value)将不会编译。 “预期A,但已收到命令[A]”

事实证明,当使用forSome {type}功能时,此Foo的A与其他A并不相同。我们所知道的是,两个A都是可排序的。 可以通过提供其他类型参数来解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM