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 EJB Certification (SCBCD/OCPJBCD) and the fly likes Collections, Serializable and legal return types 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 » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Collections, Serializable and legal return types" Watch "Collections, Serializable and legal return types" New topic
Author

Collections, Serializable and legal return types

Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

Hi Folks,
Referring to Head First EJB, pg 72.
It says
"All collection implementations of the J2SE API are Serializable"


In the same page, it says the values method of HashMap 's return Collections.
"..Map classes like HashMap and Hashtable have a values() method that returns a collection of just the values without the keys. In other words, if you called it on your HashMap, you'd get a Collection of objects.

..a collection that implements the Collection interface. But that isn't enough to to tell you whether the Collection returned by the values() method is Serializable"


I was a little confused about these two set of statements. Since all implementation's of Collection automatically become Serializable by virtue of implementing Collection, shouldn't all collections returned by values() also be guaranteed to be Serializable?


Cheers,
Roy.
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
http://cs.nyu.edu/~rpm319
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

Here's one statement:
"All collection implementations of the J2SE API are Serializable"


Here's another statement:
"...all implementation's of Collection automatically become Serializable by virtue of implementing Collection...


You seem to think those two statements are equivalent. They are not. If you check the API document for java.util.Collection you will see that Serializable is not a superinterface of it. Nevertheless it is true that all of the Collection implementations are Serializable; check their API documentation pages and you can verify that for yourself.
Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

If you check the API document for java.util.Collection you will see that Serializable is not a superinterface of it


Thanks Paul, that clears it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collections, Serializable and legal return types
 
Similar Threads
argument type for remote method
HFEJB - serializable?
Can anybody clarify this?
quick question on primary key
Dan's new Collections Questions