这是一个非常精简的版本:
case class Brickwall[A](otherSide: A)
trait Monoman { def me(m: this.type): Unit }
def test(m: Monoman): Unit = m.me(Brickwall(m).otherSide)
-> error: type mismatch;
found : Monoman
required: m.type
愚蠢的砖墙不让我通过。有什么想法可能吗? secret 的斯卡拉隧道效应?希望...
最佳答案
据我所知,Scala 编译器拒绝推断路径依赖类型,所以一点类型注释会有所帮助:
def test( m: Monoman ) { m.me( Brickwall[m.type]( m ).otherSide )}
关于scala - 通过砖墙驱动单例类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5575030/