I was recently told that collection should be preferred to List as the return value of an EJB method. The argument is that in general collection is more generic i.e. gives you to change the underlying data structure without impacting the clients. And if this is the flexibility you want to have as a designer then using collection will make better sense. But then wouldn't it make more sense to return just an array instead of collection?
And what are performance impacts if any?
Thanks in advance.
Then you usually have 4 options: List
, Set
, Collection
and Iterable
. There it depends what is the semantics you want to include.
Set
List
Collection
Iterable
(Note: there are some collection interfaces with more specific semantics: Queue
, Deque
, Map
, Bag
, Multiset
, etc. - but it will be fairly obvious when you need to return them)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With