Scala avoid using null

前端 未结 5 2009
情深已故
情深已故 2021-01-18 04:07

I hava a project on github that is analysed by codacy . The analysis suggest to \"Avoid using null\" for the following line of code:

def doS         


        
5条回答
  •  长情又很酷
    2021-01-18 04:32

    I would keep it as is. You aren't really using null here, just guarding against it. The alternative could be to just delete that line altogether, and decide to not handle the null at all. Ignoring the possibility of null might be fine in a well built code base where it shouldn't come up anyway and null would be a bug, but a simple guard to catch it could prevent more subtle bugs from showing up in case something went wrong and null actually happens.

提交回复
热议问题