Hi all, sorry but I am going to ask some dumb newbie questions. Well a question.
I am working on a project, I have never done any EJB coding before. We have an MDB that is executing and doing a lot of work. I am not overly concerend about this, however what I am worried about is that the methods of the objects that the MDB makes use of returns HashMaps.
To my mind if you wish to return more the one item from a method, a hashmap is the last object I would chose, the frist being a custome object that contains the multiply items to be returned, then perhaps an array, or a list, but never a hashmap.
This is a general Java design question so I would not categorize this as "MDB's General Questions". This is a general Java question, could be applied to anything that's java.
In my opinion the use of HashMaps are justified if you are going to search for an object stored in the map using a key. You should check what is or should be done with the HashMap after it is returned. HashMap if used correctly, i.e. the object being used as a key should have properly overridden hashcode and equals method, offers very fast object retrieval using the key. If nothing of this sort is required in your case then a normal Array or ArrayList should suffice.
You could move this post to an "Advanced Java" forum here at Javaranch and find more interesting comments.
Joined: Jan 01, 2007
Hi, The reason I asked here, was I have never seen a hashmap returned just to get around the fact that you cant return multiple items from a method, arrays, lists, composite objects yes, hashmaps never.
Of course if you have a collection of objects to return you return those in the most suitable Collection type, but there seems to be no need for the hashmap.
Somebody muttered something about it being an Enterpise Design Pattern to pass objects between application layers *shrugs*