According to the API, this is not possible. One explanation is that volatile collections are very discouraged, and immutable collections do not need default capacity information, since the number of elements must be known at build time.
However, note that Scala will implicitly use the default capacity information if you create a collection (including mutable and immutable HashMap ) using the many collection methods available. For example, if you call map on a HashMap , it will use the map defined in the TraversableLike (reproduced below), and you can see that it provides a โsize hintโ to the builder, which provides this information capacity.
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b.sizeHint(this) for (x <- this) b += f(x) b.result }
dhg
source share