Help Center

Local Navigation

Avoiding returning null

If you write a public method that returns an object, the method should return null only under the following conditions:

  • Your application expects a null value to occur during normal application operation.
  • The Javadoc™ @return parameter for the method states that null is a possible return value.

If your application does not expect a null return value, the method should throw an appropriate exception, which forces the caller of the method to deal explicitly with the problem. The caller of the method might not need to check for a null return value unless the caller of the method throws a null exception.

Index


Was this information helpful? Send us your comments.