Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

HF-eJB page no. 72

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,
I can't clearly understand the reply posted for one of the "There are no DUMB QUESTIONS" in page no. 72.
que.1: I'm sitting here with a HashMap full of serializable Customer objects with string keys. Do I have to worry about whether the HashMap itself is Serializable ?
All of the implementations of Collection interface are serializable but why would the return type of values() should be relied upon for serializability.
Any input detailing a little more on the reply is appreciated !
~ Shalini
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good question from Torean!!!i spent quite a bit of time & came up with a question on values() from hashmap returns a collection, what we can do is to fill the returned collection into an arraylist to make the objects surely serializable as the book says, but my question is ?
i went through the AbstractList class and it does not implement
the serializable interface ,may be that is why the returned collection be fed into a known collection implementing class(to make sure that the classs is serializable),
but the book says in 72-page that all collection implementations are serializable ?
please help me & Torean
thanks
 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my thought,values() method of HashMap returns Collection interface which doesn't extend serializable interface.So it is not serializable and so is not shippable.There is a way to convert Collection we get from values() method to serializable object.We can use ArrayList since this class implements Serializable.Use ArrayList constructor public ArrayList(Collection c) .

Veeba
 
Arthur, where are your pants? Check under this 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
    Bookmark Topic Watch Topic
  • New Topic