【发布时间】:2017-01-02 22:44:36
【问题描述】:
我定义了以下类:
文件:PyRef.scala:
package mypackage
class PyBinding() {
...
}
trait PyRef {
type Binding = PyBinding
}
文件:Link.scala:
class Link() extends PyRef {
override type Binding = Link.PyBindingImpl
}
object Link {
class PyBindingImpl() extends PyRef#Binding() {
}
}
编译时抛出如下错误:
Error:(222, 34) class type required but mypackage.PyBinding found
) extends PyRef#Binding() {
为什么会发生这种情况,我应该怎么做才能避免它?我正在使用 Scala 2.10。
【问题讨论】:
-
我认为您正在尝试使用 typeclasses 和 the aux pattern 构建一些东西。
-
将类型绑定声明为协变或绑定<:pybinding>
-
@tribboid ...我给了你一个糟糕的文档,这让你错过了重点。试试这个:typelevel.org/cats/typeclasses.html
标签: scala inheritance type-alias