• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serializing protected variable from super class

 
A Ridolfi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have these classes

class javax.mail.URLName{ //does not implement serializable
protected String fullUrl; //won't serialize because class is not serializable
}

I need to serialize URLName, in particular the fullUrl field. However, I am subclassing it, and the subclass DOES implement serializable.

class URL extends javax.mail.URLName implements java.io.Serializable{}

My question is: When I serialize URL (sub-class of URLName), will the inherited fullUrl field be serializable also? Are public/default/protected inherited fields automatically serialized even though the super class don't implement Serializable?

Thank you
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the readObject and writeObject methods for these:

These two methods need to work together perfectly - readObject needs to read the same type of objects as writeObject is writing, otherwise you will run into problems.

Don't worry about these methods being private, the JVM will have no problem finding these.
 
A Ridolfi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help mate!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic