Java – set vs list vs array as return type of EJB method

I was recently told that collection should take precedence over list as the return value of EJB methods The argument is that, in general, collections are more generic, allowing you to change the underlying data structure without affecting the client If this is the flexibility that designers want, it makes more sense to use collections But is it more meaningful to return only an array rather than a collection?

What is the performance impact?

Thank you in advance

Solution

>Preferred array set; Use Generics

Then you usually have four options: list, set, collection and iteratable There it depends on what semantics you want to include

>If it is an internal API – it depends on the characteristics of the collection:

>It holds only one item? Do group clients need random access? List > the client needs to modify it (add, delete) (without the above two features)? Do you only need iteration to collect customers? Iteratable

>It doesn't matter if it's a web service - it's serialized in the same way

(Note: there are some collection interfaces with more specific semantics: queue, deque, map, bag, multiset, etc. - but it will be quite obvious when you need to return them)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>