Checking for Null After New

Checking for Null After New

In lot of places, I have seen developers doing a ‘new’ to instantiate a user-defined data type (Objects) and then later in the source code checking whether this new Object is referring to null or not by doing a (Object == null).

This check is not required in Java because ‘new’ is not allowed to return null.

A new operator will raise an OutOfMerroryException if there is insufficient memory available.


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist