我想編譯這個scala代碼並得到以下編譯器警告。如何解決這個scala編譯器擦除警告?
scala> val props: Map[String, _] =
| x match {
| case t: Tuple2[String, _] => {
| val prop =
| t._2 match {
| case f: Function[_, _] => "hello"
| case s:Some[Function[_, _]] => "world"
| case _ => t._2
| }
| Map(t._1 -> prop)
| }
| case _ => null
| }
<console>:10: warning: non-variable type argument String in type pattern (String, _) is unchecked since it is eliminated by erasure
case t: Tuple2[String, _] => {
^
<console>:14: warning: non-variable type argument _ => _ in type pattern Some[_ => _] is unchecked since it is eliminated by erasure
case s:Some[Function[_, _]] => "world"
^
在How do I get around type erasure on Scala? Or, why can't I get the type parameter of my collections?上給出的答案似乎指向同樣的問題。但我無法在這個特定的背景下推斷出解決方案。
如何'x'定義? – Brian 2013-02-14 06:14:27
x可以是任何物體或功能的任何東西 – sobychacko 2013-02-14 18:05:19