DEV Community

shubham mishra
shubham mishra

Posted on • Originally published at Medium

1

Scala class inherit or extend another case class not possible

Scala case class inherit , #extend , #case class , #case class #inheritance #code #coding_question

It is not possible that we can not inherite another case class .

If you want to inherite then you can create Trait
Here we create Student Trait
case class Student(identifier: String) {}

case class SportTeam (salary: Long) extends student
Here we define a Student
trait Student{ def identifier: String }

Here we create class which is extends Student
case class SportTeam(identifier: String, salary: Long) extends Student

Case classs not able to extend of another case class because of following -

  1. It led to wrong circumstances and unexpected behaviour.
  2. It produce issue in multiple problems in the pattern matcher.
  3. Case class most consistent with inheritance would violate the spec.
  4. Scala doesn’t generate a copy method if one already exists in the class/traits the case class inherits.

Imagine monitoring actually built for developers

Billboard image

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay