Scala question - how to tell if session(VAR) is a Seq[String] or just a String?

I’m trying to write a generic debug print of a session variable value. I typically use strings and sequences of strings, only. When it is a string, I will just dump the value. When it is a sequence, I want to make it look like a bullet list on the console.

Here’s my code (so far):

def ValueOf( s : SessionVariable ) : ( Session => Validation[Session] ) = session => { println( "\n===========================================================================" ) println( "DEBUG - Value of Session Variable:" + s ) println( "---------------------------------------------------------------------------" ) val v = session( s ).as[Any] println( v match { case s : String => s case seq : Seq[String] => " - " + seq.mkString( ",\n - " ) case x => x.toString }) println( "===========================================================================" ) session }

And the compile warning I get is:

... non-variable type argument String in type pattern Seq[String] (the underlying of Seq[String]) is unchecked since it is eliminated by erasure [warn] case seq : Seq[String] => " - " + seq.mkString( ",\n - " ) [warn] ^ [warn] one warning found

Can anyone tell me what is the RIGHT way of doing what I am trying to accomplish?

Java (and Scala as a consequence) loses type parameters at runtime. That’s called type erasure.
Once again, something stupid in Java because of the Java 4 compatibility “greater good”… Java 5 was released more than 10 years ago…

As pattern matching is something that happens at runtime, Scala has no way of telling appart Seq[String], Seq[Int], Seq[Whatever], so the compiler warns you that your pattern matching might produce unexpected results.

As you actually don’t need Strings, you can simply write:

case seq: Seq[_] => seq.mkString(" - ", ",\n - ", “”)

On a whim, I tried using Seq[Any] and that also did the trick. I like the underscore trick, though. Thanks for the help. It is much appreciated.