Check if variable null before assign to null?

后端 未结 8 1090
清歌不尽
清歌不尽 2021-01-05 16:55

Is variable assignment expensive compared to a null check? For example, is it worth checking that foo is not null before assigning it null?

if (foo != null)          


        
8条回答
  •  执笔经年
    2021-01-05 17:25

    I wouldn't worry about it - it's just extra lines of code to maintain. This is the sort of micro-optimization you should never do unless you have lots of documented proof that it's your bottleneck.

提交回复
热议问题