문제

I just stumbled over the following definition of method to defined by TraversableLike (2.10.0):

override def to[Col[_]](implicit cbf: CanBuildFrom[Nothing, A, Col[A @uV]]): Col[A @uV] = {
  val b = cbf()
  b.sizeHint(this)
  b ++= thisCollection
  b.result
}

According to this answer, the @uV disabled variance checking. That sounds dangerous. Why would I want to do that?

도움이 되었습니까?

해결책

I guess the answer would be very similar to the one for this question: When is @uncheckedVariance needed in Scala, and why is it used in GenericTraversableTemplate?

Since builders (the implicit parameter cbf) exist for immutable (possibly covariant) and mutable (invariant) collections, the annotation is probably used here to make the to method work for both types of collections.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top