Hi
I have an application that 'used' to send back collections of User objects in an ArrayList. There came a time when the ArrayList was too specific and we had to get more general so we changed our prog to return a Collection. The reason for this was because there were times when we needed a HashSet to guarantee uniqueness and an ArrayList wouldn't do this without programming the uniqueness into the method that would 'add' the elements.
If I have an ArrayList that is returned as a Collection and is then down cast into a HashSet I should have no problem becuase the 'architecture' of the ArrayList / HashSet is almost the same. I.E. They mimic a one dimensional array of 'Objects'.
My problem is here.. what happens if I upcast from ArrayList to Collection (the returned type), my 'calling' program receives this Collection and down casts it into a HashMap. This is still a collection, but, it is a functional diffrent collection in the sanse that is almost mimics a 2 dimensional array of key/value pairs.
Will my HashMap be populated with the objects in the collection with null or "" keys? Or will we lost something in the cast?
I know that
you should not lose functionaly when you cast, but what about functionality that was never there to begin with?