Is it better to use List or Collection?

前端 未结 8 692
失恋的感觉
失恋的感觉 2021-02-03 19:33

I have an object that stores some data in a list. The implementation could change later, and I don\'t want to expose the internal implementation to the end user. However, the us

8条回答
  •  抹茶落季
    2021-02-03 20:14

    Returning a List is in line with programming to the Highest Suitable Interface.

    Returning a Collection would cause ambiguity to the user, as a returned collection could be either: Set, List or Queue.

提交回复
热议问题