在scala中没有右操作数的意思是什么?

问题描述:

我知道什么=>运算符的意思。 E.g Int =>布尔值,但在Trait定义中,我没有看到任何右操作数。 “self:Repr =>”是什么意思?我只能部分填补它。自我是一个变种?函数需要输入Repr并返回什么?在scala中没有右操作数的意思是什么?

trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]] extends SeqLike[A, Repr] { 
    self: Repr => 

    override protected[this] def thisCollection: LinearSeq[A] = this.asInstanceOf[LinearSeq[A]] 
    override protected[this] def toCollection(repr: Repr): LinearSeq[A] = repr.asInstanceOf[LinearSeq[A]] 

    def seq: LinearSeq[A] 

    override def hashCode()= scala.util.hashing.MurmurHash3.seqHash(seq) // TODO - can we get faster via "linearSeqHash" ? 

    override /*IterableLike*/ 
    def iterator: Iterator[A] = new AbstractIterator[A] { 
    var these = self 
    def hasNext: Boolean = !these.isEmpty 
    def next(): A = 
     if (hasNext) { 
     val result = these.head; these = these.tail; result 
     } else Iterator.empty.next() 

    override def toList: List[A] = { 
     /* Have to clear `these` so the iterator is exhausted like 
     * it would be without the optimization. 
     * 
     * Calling "newBuilder.result()" in toList method 
     * prevents original seq from garbage collection, 
     * so we use these.take(0) here. 
     * 
     * Check SI-8924 for details 
     */ 
     val xs = these.toList 
     these = these.take(0) 
     xs 
    } 
    } 
+0

我在那个链接中看到的最接近的关于=>的类型中没有左参数。但是这没有正确的参数。 此外,没有提及没有“var”或“val”前缀的这种类型的语句 –

Ravi是斯卡拉自我类型..它可以用于依赖注入。因此截至目前它并没有指向任何真正的类型,但是使用代码可以传递符合该特征的具体类型。
请参阅this