title: Scala: Return type of abstract method
body: <p>I cannot figure out how to specify the return type of a method an abstract class A, if the same method of the concrete classes have different return (sub)types:</p>
  
  <pre><code>abstract class A {
      def method: List[Common (?)]   // I want to force all subclasses to define this method
  }
  
  class B1 extends A {
      def method(a,b,c): List[Sub1] = {...}
  }
  
  class B2 extends A {
      def method(a,b,c): List[Sub2] = {...}
  }
  </code></pre>
  
  <p>I tried to define a common trait of <code>Sub1</code> and <code>Sub2</code>:</p>
  
  <pre><code>abstract class Common   // or abstract class
  case class Sub1 extends Common
  case class Sub2 extends Common
  </code></pre>
  
  <p>but I keep getting this:</p>
  
  <pre><code>Compilation error[class B1 needs to be abstract, 
  since method "method" in class A of type =&gt; List[Common] is not defined]
  </code></pre>
  
  <p>If I don't define the return type in class A, I get the same error with <code>... type =&gt; Unit ...</code> instead.</p>
  
  <p>How can I solve that?</p>