Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Stuff about serializable

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about Serialization. What are the conditions for an object to be serializable?
I know that all member variable in the object must be a primitive type, String or Serializable object.

Does the method's return value and argument need to be serializable too?

What if the body of a method uses an object that is not serializable?

example:


Thank you
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only the object in question is being serialized--the return values of methods, or objects used inside methods, have nothing to do with it.
 
Marshal
Posts: 69738
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to check in the Java Language Specification, but I think it is only the instance fields which have to be serializable. It is not a case of primitive, String or Serializable. A String is a Serializable. So is an array (provided its elements are Serlalizable). You can check any class in the API because it will say "implements Serializable" near the top of the page for that class.
 
Bill Lee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help guys.
 
Campbell Ritchie
Marshal
Posts: 69738
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic