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?
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.
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
posted 15 years ago
Thanks Terry and Kathy for the explaination.
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop