| 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.
SCJP 1.5, SCWCD 5.
"Perseverance is the hard work you do after you get tired of doing the hard work you already did"
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 13842
|
|
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.
|
 |
 |
|
|
subject: Collections, Serializable and legal return types
|
|
|