Case Classes - Scala Documentation


Case classes are like regular classes with a few key differences which we will go over. Case classes are good for modeling immutable data. In the next step of the tour, we’ll see how they are useful in pattern matching.

This is a companion discussion topic for the original entry at


The link at the top (second line) appears to be broken.


@micseydel you mean the link to Pattern Matching?


Yes, the href is http://docs.scala-lang.orgpattern-matching.html/


I see that’s the case in this thread but when I go back to the original page, the link seems to work. Can you try it again from the original page? Perhaps try a hard refresh.


The original page is fine, other than an extra slash -

I’m not sure where you suggest a hard refresh. Does this page look alright after one? It still looks broken to me in an incognito window. I don’t think it’s a caching issue, either the link is wrong or there’s a bug in whatever you’re using to copy things.


You can create a deep copy of an instance of a case class simply by using the copy method

Umm… Isn’t a case class copy() actually a shallow copy?

Given they are almost invariably immutable a deep copy would be an incredibly bad idea.


Maybe a good idea to include in this page an example of what a case class corresponds to in terms of a regular class (toString(), equals(), copy(), …)?


yes, good catch. fixed in


But then it’s followed by “you can optionally change the constructor arguments”, which does use a deep copy, it may be worth clarifying that fact


Not sure what you mean


What I mean is that I don’t think it’s clear with the current wording that:

val myClone       = myCaseClass.copy()          // uses shallow copy
val myAlternative = myCaseClass.copy(foo = bar) // uses deep copy


Both of those do shallow copies. “Deep” copying refers to recursively copying nested objects.


Oh I see, my bad: I guess references don’t need to be cloned indeed