This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB - serializable?

 
Kiran Kumar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

This is reference to the explaination given in page 72 of HFEJB. The author says that "All of the Collection implementations in the J2SE API are serializable". After a paragraph, it says, "But what type of collection? .. .But that doesn't enough to tell you whether the collection returned by values() is Serializable!"

My questions is, if all the Collection implementations are serializable, the why does the author say, we are not sure if the collection returned by values() is serializable or not?

Am I understanding something incorrectly?

Thanks,
Kiran
 
Terry Mullett
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The concrete collection classes that you see in the java.util package may be serializable, but that doesn't mean that the object returned by any method with a return type of "Collection" will be. This is because that return type is not necessarilly one of those top level public classes. It could well be an inner class of the object the method is on, or a package-level class not meant to be intimately known by its client. The point is, if you know that the class implementing the Collection interface is a specific public class, you can tell whether it's serializable. Otherwise, you can't count on it.
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Terry's right--I made that kind of confusing, but what Terry said is correct. 99% of the time you won't have to worry about it -- the implementation classes you see in the API (ArrayList, HashMap, etc.) are ALL Serializable. The one non-Serializable collection I've found (but there may be others) is that inner class Collection implementation returned by a call to values(). So that's the only one I've personally encountered as a developer, and again-- ALL the API classes are Serializable. For the exam (and real life), know that you are free to use any of the declared Collection classes in a remote method call argument or return value, assuming the things you put IN the Collection are Serializable.

cheers (and thanks Terry!)
Kathy
 
Kiran Kumar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Terry and Kathy for the explaination.

Regards,
Kiran
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic