• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Serializing protected variable from super class  RSS feed

 
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
 
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!