title: Scala pattern matching confusion with Option[Any]
body: <p>I have the following Scala code.</p>
  
  <pre><code>import scala.actors.Actor
  
  object Alice extends Actor {
    this.start
    def act{
      loop{
        react {
          case "Hello" =&gt; sender ! "Hi"
          case i:Int =&gt; sender ! 0
        }
      }
    }
  }
  object Test {
    def test = {
      (Alice !? (100, "Hello")) match {
        case i:Some[Int] =&gt; println ("Int received "+i)
        case s:Some[String] =&gt; println ("String received "+s)
        case _ =&gt;
      }
      (Alice !? (100, 1)) match {
        case i:Some[Int] =&gt; println ("Int received "+i)
        case s:Some[String] =&gt; println ("String received "+s)
        case _ =&gt;
      }
    }
  }
  </code></pre>
  
  <p>After doing <code>Test.test</code>, I get the output:</p>
  
  <pre><code>scala&gt; Test.test
  Int received Some(Hi)
  Int received Some(0)
  </code></pre>
  
  <p>I was expecting the output </p>
  
  <pre><code>String received Some(Hi)
  Int received Some(0)
  </code></pre>
  
  <p>What is the explanation?</p>
  
  <p>As a second question, I get <code>unchecked</code> warnings with the above as follows:</p>
  
  <pre><code>C:\scalac -unchecked a.scala
  a.scala:17: warning: non variable type-argument Int in type pattern Some[Int] is unchecked since it is eliminated by erasure
        case i:Some[Int] =&gt; println ("Int received "+i)
               ^
  a.scala:18: warning: non variable type-argument String in type pattern Some[String] is unchecked since it is eliminated by erasure
        case s:Some[String] =&gt; println ("String received "+s)
               ^
  a.scala:22: warning: non variable type-argument Int in type pattern Some[Int] is unchecked since it is eliminated by erasure
        case i:Some[Int] =&gt; println ("Int received "+i)
               ^
  a.scala:23: warning: non variable type-argument String in type pattern Some[String] is unchecked since it is eliminated by erasure
        case s:Some[String] =&gt; println ("String received "+s)
               ^
  four warnings found
  </code></pre>
  
  <p>How can I avoid the warnings?</p>
  
  <p>EDIT: Thanks for the suggestions. Daniel's idea is nice but does not seem to work with generic types, as in the example below</p>
  
  <pre><code>def test[T] = (Alice !? (100, "Hello")) match { 
     case Some(i: Int) =&gt; println ("Int received "+i) 
     case Some(t: T) =&gt; println ("T received ") 
     case _ =&gt;  
  }
  </code></pre>
  
  <p>The following <strike>error</strike> warning is encountered: <code>warning: abstract type T in type pattern T is unchecked since it is eliminated by erasure</code></p>