Should I extend ArrayList to add attributes that isn't null?

前端 未结 4 814
孤街浪徒
孤街浪徒 2020-12-30 09:45

I would like to add a collection of objects to an arrayList ,only if the particular attribute is not null.

I am thinking of extending the ArrayList and implementing

4条回答
  •  长发绾君心
    2020-12-30 10:36

    If you would like to enforce this I don't see why not (although you should check the return value of the add method whenever you do add to make sure that it succeeded).

    This is a good way to get rid of that redundant logic which may or may not stick around in later software iterations.

提交回复
热议问题