Is it better to use List or Collection?

前端 未结 8 697
失恋的感觉
失恋的感觉 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:37

    Using the most general type, which is Collection, makes the most sense unless there is some explicit reason to use the more specific type - List. But whatever you do, if this is an API for public consumption be clear in the documentation what it does; if it returns a shallow copy of the collection say so.

提交回复
热议问题