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

前端 未结 4 823
孤街浪徒
孤街浪徒 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:41

    I don't think this is a good practice. Consider instead writing a Util-Method in a Util-Class taking two parameters: The array list and the object you would like to add. There you can check whatever you want and can reuse the logic all over your code.

提交回复
热议问题