Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF-eJB page no. 72

 
Ashok Paulraj
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
 
pradeep arum
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
 
Veena Pointi
Ranch Hand
Posts: 442
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic