在Scala中,你如果使用了泛型的话,那你在Pattern Matching的时候要注意了,因为会有类型擦除的问题:non variable type-argument String in type pattern is unchecked since it is eliminated by erasure,这是由于JVM导致的。
不过Scala也提供了Manifest这样的类来处理这样问题,详细请参考:[url=http://stackoverflow.com/questions/1094173/how-do-i-get-around-type-erasure-on-scala-or-why-cant-i-get-the-type-parameter]How do I get around type erasure on Scala? Or, why can’t I get the type parameter of my collections?[/url]
这里要说得是Actor导致的Pattern Matching问题,因为在act中你没有处理Manifest的机会,因此,在Actor中常用的方法是把你的泛型数据通过case class进行包装,就可以比较优雅的解决问题了:
不过Scala也提供了Manifest这样的类来处理这样问题,详细请参考:[url=http://stackoverflow.com/questions/1094173/how-do-i-get-around-type-erasure-on-scala-or-why-cant-i-get-the-type-parameter]How do I get around type erasure on Scala? Or, why can’t I get the type parameter of my collections?[/url]
这里要说得是Actor导致的Pattern Matching问题,因为在act中你没有处理Manifest的机会,因此,在Actor中常用的方法是把你的泛型数据通过case class进行包装,就可以比较优雅的解决问题了:
case class RangeNodes(nodes:Array[NodeTuple])
....
receiveWithin(10000) {
case RangeNodes(ipSet) => nodes ++= ipSet
}