0

So, I was studying serialization and I got to know about us having the ability to override the above stated methods.I was wondering,how could I use it? One idea that came to my mind is maybe encrypting and decrypting the data while writing and reading.I am not sure though,if it is how it finds its application. As a developer, how would you use it?

kars
  • 3
  • 2

1 Answers1

0

So, on further research,I found out an application of overriding readObject() and writeObject() methods under the Serialization interface, that finds it significant use in Android Development due to performance overheads.

So,the Serializable interface in JAVA internally uses reflection to serialize objects. Reflection leads to creation of lot of objects and hence possess large performance overheads.But if the given methods are overridden, so as to minimize the garbage collection expenses,the serialization reads and writes can be performed significantly faster.

For instance, Android allows the implementation of a Parcelable interface which tries to do away with Reflection.As expected it performs significantly better in the default implementation of the methods.But it is observed that on overriding the readObject() and writeObject() methods makes it significantly faster than the default ones.

Reference:Parcelable vs Serializable

kars
  • 3
  • 2