new
keyword,toString
method is automatically redefined to print the name of the case class and all its arguments,equals
method is automatically redefined to compare two instances of the same case class structurally rather than by identity.hashCode
method is automatically redefined to use the hashCode
s of constructor arguments.Most of the time you declare a class as a case class because of point 1, i.e. to be able to do pattern matching on its instances. But of course you can also do it because of one of the other points. The code example below makes use of two of the characteristics of case classes [1]:
new
keyword (point 2), for example in List(MyInt(1), MyInt(2), MyInt(3))
else m.asInstanceOf[MyInt].x == x;
Links:
[1] http://www.scala-lang.org/node/107