In scaladoc, BitSet
is defined as an extension of Set[Int]
. Therefore, I thought that using BitSet
, as in the case of Set[Int]
, would work, but I get a type mismatch:
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29). scala> import collection.BitSet import collection.BitSet scala> val b: Set[Int] = BitSet() <console>:8: error: type mismatch; found : scala.collection.BitSet required: Set[Int] val b: Set[Int] = BitSet() ^
However, casting works:
scala> val b: Set[Int] = BitSet().asInstanceOf[Set[Int]] b: Set[Int] = BitSet()
So, why should I explicitly highlight BitSet
in Set[Int]
, and Set[Int]
is the supertype of Set[Int]
?
source share