Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between scala @Serializable and Java Serializable?

the manner of action of scala @Serializable is different from Java Serializable?

I mean the way to serialize objects or both use the same standard serialization?

like image 983
ricardogobbo Avatar asked Jun 22 '11 17:06

ricardogobbo


People also ask

What is serializable in Scala?

Serializing an object means taking the data stored in an object and converting it to bytes (or a string). Suppose you want to write the data in an object to a JSON file. JSON files store strings. JSON has no understanding about the JVM or Scala objects.

What is difference between serializable and Externalizable?

Serializable interface passes the responsibility of serialization to JVM and the programmer has no control over serialization, and it is a default algorithm. The externalizable interface provides all serialization responsibilities to a programmer and hence JVM has no control over serialization.

Is Scala case class serializable?

All case classes automatically extend Product and Serializable . It looks ugly ? yes. Basically , Product can be viewed as heterogeneous collections.

What is difference between using serializable and Externalizable interfaces in Java?

Externalization provides implementation logic control to the application by overriding readExternal and writeExternal methods. In serializable interface uses reflection which causes relatively slow performance. Externalizable gives full control over the implementation approach.


1 Answers

Well Scala compiles to JVM byte code, so the only difference comes from how Scala implements this conversion. Scala converts the annotation to the interface during type checking which can lead to some subtle problems see here.

Afaik @Serializable is deprecated anyhow - compared to other annotations (volatile annotation instead of a specifier) in scala I don't see much advantages anyhow.. doesn't make the code much clearer or simpler.

like image 113
Voo Avatar answered Nov 01 '22 18:11

Voo