title: Scala case classes and equals method
body: <p>I have a question concerning Scala case classes. I have a case class that is a composition of other types as below:</p>
  
  <pre><code>case class MyCaseClass(typeA: TypeA, typeB: TypeB) {
   override def equals(obj: scala.Any): Boolean = super.equals(obj) // generated by intelliJ
  }
  </code></pre>
  
  <p>Both my TypeA and TypeB are normal Scala classes and what I want is that, two instances of MyCaseClass is equal only if all the properties of typeA and typeB are equal. I could of course do this check in the equals method directly in my case class like below:</p>
  
  <pre><code>case class MyCaseClass(typeA: TypeA, typeB: TypeB) {
  ....
    def equals(obj: Any): Boolean = obj match {
      case myCase: MyCaseClass =&gt; myCase.typeA.equals(myCase.typeB)
      case _ =&gt; false
    }
  }
  </code></pre>
  
  <p>With respect to the example snippet above, I have the following questions:</p>
  
  <ol>
  <li><p>If my TypeA is a case class and my TypeB is a normal Scala class, would this means that I have to implement equals method just in TypeB where in my TypeA being a case class would get the equals method by default and I do not have to provide one?</p></li>
  <li><p>My MyCaseClass would be used in such a way that I have a sequence of MyCaseClass and a primitive value (Double or Integer) as a tuple Seq(MyCaseClass, Double). Now if I do a groupBy operation on MyCaseClass from the Sequence, will they be groupedBy based on the equals method? </p></li>
  </ol>