Java: How to check for null pointers efficiently

前端 未结 14 1799
清歌不尽
清歌不尽 2020-12-03 01:17

There are some patterns for checking whether a parameter to a method has been given a null value.

First, the classic one. It is common in self-made code

14条回答
  •  心在旅途
    2020-12-03 02:01

    Aren't you optimizing a biiiiiiiiiiiiiiit too prematurely!?

    I would just use the first. It's clear and concise.

    I rarely work with Java, but I assume there's a way to have Assert only operate on debug builds, so that would be a no-no.

    The third gives me the creeps, and I think I would immediately resort to violence if I ever saw it in code. It's completely unclear what it's doing.

提交回复
热议问题