Good or bad practice? Initializing objects in getter

前端 未结 9 1781

I have a strange habit it seems... according to my co-worker at least. We\'ve been working on a small project together. The way I wrote the classes is (simplified example):<

9条回答
  •  眼角桃花
    2020-12-07 07:47

    The downside that I can see is that if you want to ask if Bars is null, it would never be, and you would be creating the list there.

提交回复
热议问题