Function returns: Collection vs Array
Hi Guys
I just wanted to gather some opinions on function returns. Do you think its better to return a Collection or an Array?
What are the advantages / disadvantages of each?
If you were building a mid sized application for your organization, would you go for a Collection of Array. eg Your DAO has a method called listAllTasks, should this return an Array or Strongly Typed Collection?
Thanks
Josh
> I just wanted to gather some opinions on function
> returns. Do you think its better to return a
> Collection or an Array?
The best thing to return may be a dedicated type, but in the choise between the ones you mention I would pick the interface Collection<E>.
It gives the provider of the information the greatest flexibility. He can return any a collection like an ArrayList or a HashSet or whatever.
It's then up to the user of this information to maybe "reload" it into some other data structure suitable for his processing needs.
You may even specify that the Collection<E> should be made unmodifiable before it's return to make sure nobody messes with it if it's passed around.