Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7645375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:55:34+00:00 2026-05-31T09:55:34+00:00

In the scaladoc, BitSet is defined as extending Set[Int] . So I thought using

  • 0

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]?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:55:36+00:00Added an answer on May 31, 2026 at 9:55 am

    It turns out that your Set is actually scala.collection.immutable.Set. So you can

    val b0: Set[Int] = collection.immutable.BitSet()
    val b1: collection.Set[Int] = collection.BitSet()
    val b2: collection.immutable.Set[Int] = collection.immutable.BitSet()
    val b3: collection.mutable.Set[Int] = collection.mutable.BitSet()
    val b4: collection.Set[Int] = collection.immutable.BitSet()
    val b5: collection.Set[Int] = collection.mutable.BitSet()
    

    but not any of

    val x1: collection.immutable.Set[Int] = collection.BitSet()
    val x2: collection.immutable.Set[Int] = collection.mutable.BitSet()
    val x3: collection.mutable.Set[Int] = collection.BitSet()
    val x4: collection.mutable.Set[Int] = collection.immutable.BitSet()
    

    and it turns out that the default import for Set gives you x2. Import collection.immutable.BitSet, or import collection.Set (to cover collection.immutable.Set).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is in ScalaDoc but without much documentation. It seems that it always returns
According to Scaladoc, there is no method named map in Array class, but there
The ScalaDoc for the applet class is pretty thin on details on how you
Idle pondering from a Scala learner perhaps, but ... in my tinkerings I've written
According to scaladoc, sliding() returns... An iterator producing iterable collections of size size ,
I binged or googled for scaladoc 2.0 tutorial or example, I could not find
In the Scaladoc of class Enumeration#Val, I can read: A class implementing the Value
Looking at the scaladoc for Traversable and TraversableLike, I'm having a hard time figuring
How do I install the antlib.xml for scala to get ant working? Right now
Is there any way you can make IntelliJ wrap scaladoc at the margin? Basically,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.