Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Collections, Serializable and legal return types

 
Ranch Hand
Posts: 35
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 26291
80
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic