Scala自我类型与依赖键入

前端之家收集整理的这篇文章主要介绍了Scala自我类型与依赖键入前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这不编译:

trait FileSystem {
    type P <: Path[this.type]
}

trait Path[S <: FileSystem] { self: fileSystem.P =>
    val fileSystem: S
}

自我类型约束如何依赖于该特征中的值成员?

解决方法

它不能(并且不确定它意味着什么).

trait FileSystem {
    type P <: Path[this.type]
}

trait Path[S <: FileSystem] { self: S#P =>
    val fileSystem: S
}

猜你在找的Scala相关文章