In the scaladoc, BitSet
is defined as extending Set[Int]
. So I thought using a BitSet
as in instance 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 a cast works:
scala> val b: Set[Int] = BitSet().asInstanceOf[Set[Int]]
b: Set[Int] = BitSet()
So why do I need to explicitely cast a BitSet
to a Set[Int]
while Set[Int]
is a super-type of Set[Int]
?