Reputation: 3515
My sbt is showing a warning message
non-variable type argument String in type pattern List[String] (the underlying of List[String]) is unchecked since it is eliminated by erasure
I tried the answer given in the link (first solution)
Here is my code
case class ListStrings(values:scala.List[String]) { }
def matchValue(value: Any) = {
value match {
case ListStrings(xs) =>
val userList = xs
case _ => log.error("unknown value")
}
}
val list: List[String] = List("6","7","8")
matchValue(list)
I am getting "unknown value" as an output why its not matching ? what i am missing here?
Upvotes: 0
Views: 251
Reputation: 14803
First with this it works:
val list = ListStrings(List("6" ,"7","8"))
So you see the problem.
To achieve this, the simplest is maybe to add an apply
constructor:
object ListStrings {
def apply(values: String*): ListStrings = ListStrings(values.toList)
}
Now you can call it like:
val list = ListStrings("6" ,"7","8")
Upvotes: 0