Initialize a collection within an object?

后端 未结 10 1268
长发绾君心
长发绾君心 2021-02-04 15:03

If an object has a property that is a collection, should the object create the collection object or make a consumer check for null? I know the consumer should not assume, just

10条回答
  •  佛祖请我去吃肉
    2021-02-04 15:32

    If the collection is an intrinsic part of the object, then the object should generally create it (and not allow the user to set it to a different collection instance).

提交回复
热议问题