This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections, Serializable and legal return types

 
Royston Monteiro
Ranch Hand
Posts: 35
Java Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Clapham
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
Java Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic