title: unapply method of a case class is not used by the Scala compiler to do pattern matching, why is that?
body: <pre><code>abstract class Animal
  
  case class Cat(name: String) extends Animal
  
  case class Dog(name: String) extends Animal
  </code></pre>
  
  <p>Say I have defined Cat and Dog, two case classes.</p>
  
  <p>Then I use them like this:</p>
  
  <pre><code>val animal = createAnimal
  animal match {
    case Dog(anyName) =&gt; "this is a dog"
    case Cat("kitty") =&gt; "this is a cat named kitty"
    case _ =&gt; "other animal"
  }
  </code></pre>
  
  <p>If I decompile the bytecode to Java, I get something like this:</p>
  
  <pre><code>Animal animal = createAnimal();
  String result = "other animal";
  
  if (animal instanceof Dog) {
      result = "this is a dog";
  } else if (animal instanceof Cat) {
      Cat cat = (Cat) animal;
      if (cat.name() == "kitty") {
          result = "this is a cat named kitty";
      }
  }
  
  return result;
  </code></pre>
  
  <p>The compiler generates unapply methods for both Cat and Dog, but they are not used in the pattern matching code.</p>
  
  <p>Why is that?</p>