Skip to content

Commit 759c6d8

Browse files
committed
Add a comment to HashMap.castToThat
1 parent c0f094d commit 759c6d8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/src/scala/collection/immutable/HashMap.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ sealed class HashMap[A, +B] extends AbstractMap[A, B]
237237
castToThat(result)
238238
}
239239
}
240+
241+
// These methods exist to encapsulate the `.asInstanceOf[That]` in a slightly safer way -- only suitable values can
242+
// be cast and the type of the `CanBuildFrom` guides type inference.
240243
private[this] def castToThat[C, That](m: HashMap[A, B])(implicit bf: CanBuildFrom[HashMap[A, B], C, That]): That = {
241244
m.asInstanceOf[That]
242245
}

0 commit comments

Comments
 (0)