title: scala generic function return type
body: <p>I tried writing a function with a generic return type but it doesn't work unless I cast the return type. Please see the function <code>getSomething()</code> below I expected it to work without the casting. What might I be doing wrong here? </p>
  
  <pre><code>trait Sup
  
  class Sub extends Sup {
    def getString = "I am Sub"
  }
  
  class Sub2 extends Sup {
    def getInt = 100
  }
  
  def getSomething[A &lt;: Sup](str: String) : A  = {
    str match {
      case "sub" =&gt; getSub.asInstanceOf[A]
      case "sub2" =&gt; getSub2.asInstanceOf[A]
    }
  }
  
  def getSub(): Sub = {
    new Sub
  }
  
  def getSub2() : Sub2 = {
    new Sub2
  }
  
  val x = getSomething[Sub]("sub").getString
  val y = getSomething[Sub2]("sub2").getInt
  </code></pre>