This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Stuff about serializable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stuff about serializable" Watch "Stuff about serializable" New topic
Author

Stuff about serializable

Bill Lee
Greenhorn

Joined: Nov 25, 2006
Posts: 3
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
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Only the object in question is being serialized--the return values of methods, or objects used inside methods, have nothing to do with it.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
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

Joined: Nov 25, 2006
Posts: 3
Thanks for the help guys.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stuff about serializable
 
Similar Threads
Diff. Between Comparable & Comparator Interface
Database Schema / Facade Interface
Porting my enum type from Hibernate2 to Hibernate3
Serialization Issue
Why java.util.Set is not Serializable?