I am looking at the source code for Scala's mutable ListBuffer here https://github.com/scala/scala/blob/v2.11.8/src/library/scala/collection/mutable/ListBuffer.scala#L158
and I ran into this cast on line 158. I have been unable to figure out what .asInstanceOf[::[A]] means. :: is not a bounds notation that I could find in the documentation. But, it is a method for a List. Can anyone explain what this cast is doing?
::is a list constructor that is composed of head and tail (as opposed toNilwhich has neither). In other words it's a kind of list that guarantees that it contains at least one element (head).You can find its definition in
List.scala: https://github.com/scala/scala/blob/v2.11.8/src/library/scala/collection/immutable/List.scala#L439So what this cast does is that it turns the
cursortyped asList[A]into more specific::[A], that allows accessing itstlvariable, representing list tail. Which is necessary for efficientupdateoperation.