I am using scala.Serializable, but when i invoke String.asInstanceOf[Serializable], class cast exception is thrown. Here is my code, pretty simple.
arguments.map(_.asInstanceOf[Serializable])
Yes, arguments is array of string of course
I am run the application with scala-ide for eclipse with eclipse 3.7 and scala 2.9.0-1
looking into this documentation scala doc
The Problem now is "what is the typical use case of scala.Serializable"
To add to what Ricky Clarkson said, this works
scala> "hi".asInstanceOf[java.io.Serializable]
res7: java.io.Serializable = hi
but this doesn't,
scala> "hi".asInstanceOf[scala.Serializable]
java.lang.ClassCastException: java.lang.String cannot be cast to scala.Serializable
...
Without qualification, Serializable
in Scala refers to scala.Serializable
. Note that strings in Scala are of type java.lang.String
; they are "native" to the JVM and don't know about Scala. According to the API docs, the Scala serializable trait exists for cross platform compatibility (Java and .NET). If you're just on the JVM, then java.io.Serializable
should be sufficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With