One little trick I like to use for this problem is type aliasing.
type MyBuffer = ListBuffer[String]
//...
def receive = {
case x: (String, MyBuffer) if(x._2.size >= 0) => {
//.....
//.....
}
Domanda
I have an Akka Actor that has the following case pattern match check in its receive method as below:
def receive = {
case x: (String, ListBuffer[String]) if(x._2.size >= 0) => {
.....
.....
}
When I compile, I get to see the following compiler warnings:
warning: non-variable type argument String in type pattern (String, scala.collection.mutable.ListBuffer[String])
is unchecked since it is eliminated by erasure)
Any clues as to how I could get rid of them? I do not want to set the compiler settings to ignore these warnings, but I do not see a reason why the compiler issues a warning?
Soluzione 2
One little trick I like to use for this problem is type aliasing.
type MyBuffer = ListBuffer[String]
//...
def receive = {
case x: (String, MyBuffer) if(x._2.size >= 0) => {
//.....
//.....
}
Altri suggerimenti
This is due to the JVM's type erasure. At runtime, the JVM only sees ListBuffer[Any]
. Static type information of generics is lost. If you don't care about the generic type of the ListBuffer, you can change the pattern match to:
case x: (String, ListBuffer[_]) if(x._2.size >= 0) =>