How to avoid null checking in Java?

后端 未结 30 4200
失恋的感觉
失恋的感觉 2020-11-21 04:43

I use object != null a lot to avoid NullPointerException.

Is there a good alternative to this?

For example I often use:



        
30条回答
  •  佛祖请我去吃肉
    2020-11-21 05:19

    Rather than Null Object Pattern -- which has its uses -- you might consider situations where the null object is a bug.

    When the exception is thrown, examine the stack trace and work through the bug.

提交回复
热议问题