Valentin Tihomirov
Valentin Tihomirov

Reputation: 1

What is the point of Serializable interface?

Here is a runnable demo

import java.io._

object Main extends App {
    case class Value(s: String)
    val serializer = new ObjectOutputStream(new ByteArrayOutputStream())
    serializer.writeObject(Value("123"))
    println("success")                        //> success

}

Please note that program succeeds despite I do not mark my class with Serializable. Does Serializable make sense in Scala?

Upvotes: 0

Views: 68

Answers (1)

marios
marios

Reputation: 8996

Case classes extend Serializable by default in Scala. If you create a regular class it will need to extend Serializable otherwise it will throw a serialization error.

Upvotes: 4

Related Questions