Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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?
 
Sheriff
Posts: 26963
84
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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic