• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serializable Method contains Any method

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read serializable interface has no methods.Then how we can override readObject() and writeObject() methods.
Except Serializable and Externalizable interface can we do serialization.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You aren't overriding readObject(), you're just providing it. If it's there then it's used, if it's not then the default behaviour is used (which basically involves trying to serialize every member variable that's not marked transient).

If Serializable declared the methods then you'd have to implement them. This way you only implement them when you need to (which is usually when you want to serialize a member variable that's not serializable).
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajendra Prakash wrote:I read serializable interface has no methods.Then how we can override readObject() and writeObject() methods.

The interface has no methods nor any fields but serves only to identify the semantics of being serializable. Check out the Marker Interface.

Except Serializable and Externalizable interface can we do serialization.

There are many other ways like XStream, XmlEncoder etc
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic