Skip to content

Files

Latest commit

 

History

History
11 lines (6 loc) · 621 Bytes

ReturnsNullInsteadOfEmptyArray.md

File metadata and controls

11 lines (6 loc) · 621 Bytes

Pattern: Return of null instead of empty array

Issue: -

Description

If you have a method or closure that returns an array, then when there are no results return a zero-length (empty) array rather than null. It is often a better design to return a zero-length array rather than a null reference to indicate that there are no results (i.e., an empty list of results). This way, no explicit check for null is needed by clients of the method.

Further Reading