title: Scala case matching Any with String
body: <p>When I try to match an <code>Any</code> with a String, I don't get the correct output. My code looks like:</p>
  
  <pre><code>def typecast(cls: Any) {
      cls match {
          case s: String =&gt; println("string")
          case d: Double =&gt; println("double")
          case i: Int =&gt; println("int")
          case o: Option[_] =&gt; println("option")
          case _ =&gt; println("nothing")
      }
  }
  </code></pre>
  
  <p>If <code>cls</code> is of type <code>Double</code> or <code>Int</code>, the correct case is matched, but of type <code>String</code> or <code>Option[_]</code> the case _ is matched (println("nothing")). </p>
  
  <p>Any ideas why this isn't working or what I'm doing wrong? Thanks in advance!</p>
  
  <p><strong>EDIT:</strong> it works fine, if I do e.g. <code>typecast("foo")</code> or <code>typecast(Some("foo"))</code>, but in my case the <code>cls</code> value is received like:</p>
  
  <p><code>val cls: Any = classOf[User].getDeclaredField("name")</code></p>
  
  <p>where the field could be a <code>String</code> or <code>Option[String]</code></p>