-1
我知道什麼=>運算符的意思。 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
}
}
我在那個鏈接中看到的最接近的關於=>的類型中沒有左參數。但是這沒有正確的參數。 此外,沒有提及沒有「var」或「val」前綴的這種類型的語句 –