title: Understanding Case class and Traits in Scala
body: <p>I have a simple trait as defined below:</p>
  
  <pre><code>trait MyTrait {
  
    def myStringVal: String
  
  }
  </code></pre>
  
  <p>My case class which implements this trait is as below:</p>
  
  <pre><code>case class MyCaseClass(myStringVal: String) extends MyTrait {
    ...
    ...
  }
  </code></pre>
  
  <p>Coming from a Java world, I find it a bit difficult to fathom the fact that MyCaseClass actually implements this just by defining a parameter to MyCaseClass. I understand that thy byte code would actually write the getter and setter. But how is this possible without any var or val?</p>
  
  <p>My understanding is that if there is no var or val, then there is no getter or setter method generated. In that case how is the above case class MyCaseClass implementing myStringVal method?</p>
  
  <p>Sometime too much of this Scala magic is difficult to understand especially with legacy code.</p>