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 9202941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:22:05+00:00 2026-06-17T23:22:05+00:00

I created an abstract base class as follows: abstract class parent Then I went

  • 0

I created an abstract base class as follows:

abstract class parent

Then I went ahead and created two case classes inheriting from the parent class:

case class child1(name:String,category:String) extends parent

case class child2(name:String,category1:String,category2:String) extends parent

Then for kicks I created a list of type parent and appended child1 and child2 to it:

val childList = List[parent]()

scala> child1("Child","One") :: child2("Child","Two","dhshs")::childList
res2: List[parent] = List(child1(Child,One), child2(Child,Two,dhshs))

So far so good, the List[Parent] has the two child types in it.

Now, I want to traverse the List and based on the underlying type of the child, do something special for that particular type. So I do this:

scala> res2 map {case child1 => "Child1";case child2 => "Child2"}

I expected to see a List[String]("Child1","Child2"), instead I got the following:

<console>:15: error: unreachable code
              res2 map {case child1 => "Child1";case child2 => "Child2"}

Now for some more kicks, I did the following:

scala> res2 map {r => r match {case child1 => "Child1"}}
res8: List[java.lang.String] = List(Child1, Child1)

scala> res2 map {case child1 => "Child1"}
res9: List[java.lang.String] = List(Child1, Child1)

As you can see, I got “Child1” as my List entry, even for “child2” I get a Child1.

Pretty confused, can somebody tell me whats going on here?

  • 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-06-17T23:22:06+00:00Added an answer on June 17, 2026 at 11:22 pm

    The problem is here: child1 and child2 are new variables created to house the result.

    res2 map {case child1 => "Child1";case child2 => "Child2"}
    

    try this:

    res2 map {case x:child1 => "Child1";case y:child2 => "Child2"}
    

    x and y are the variables with the associated types child1 and child2 respectively.

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

Sidebar

Related Questions

I have a stateless, abstract base class from which various concrete classes inherit. Some
I have created an abstract base class Animal which has public virtual abstract method
I have created a BasePage class that inherits from System.Web.Ui.Page. In that base class
I have created an abstract base class, which has a pure virtual method with
Let's say in some abstract ViewModel base-class I have a plain-old property as follows:
I've created a abstract base class Page that figures out how to construct a
I have a class that inherits from an abstract base class. I am trying
I created an abstract base class. It contains an object which should be extended
I have many classes inherited from the abstract base SysLaserBase. I add every laser
I am trying to create a class in VB.NET which inherits a base abstract

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.