i am using elasticsearch rest api search code which gives the search response here is how i was doing earlier
if (hitmap.containsKey("UserList")) {
hitmap.get("UserList") match {
case list:java.util.ArrayList[String] => val userlist = list.asScala
userList.clear()
for (number <- userlist) {
userList += number
}
}
}
everything works fine outputs is as expected but sbt shows a warning message
non-variable type argument String in type pattern java.util.ArrayList[String] is unchecked since it is eliminated by erasure
[warn] case list:java.util.ArrayList[String] => val userlist = list.asScala
[warn] ^
after doing some research i found a way to resolve it with ClassTag
while taking help from here
How do I get around type erasure on Scala? Or, why can't I get the type parameter of my collections?
my code becomes
import scala.reflect.{ClassTag, classTag}
def matchList2[A : ClassTag](list: java.util.ArrayList[A]) = list match {
case strlist: java.util.ArrayList[String @unchecked] if classTag[A] == classTag[String] => println("A List of strings!")
}
now here the problem arises how can i convert hitmap.get("UserList")
(which returns object here) to java.util.ArrayList[String]
without using asInstanceOf
to pass a parameter to matchList2 function also i cannot use pattern match so what would be the best solution over here