commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh Foure <>
Subject [all] Null vs. Empty Lists
Date Wed, 11 Jan 2006 14:43:28 GMT
Hi all,

I have noticed that a lot of the commons libraries
return empty Lists instead of null when a method is
declared to return a List and  there are no results. 
I have also noticed this in other libraries such as
Xerces and Xalan.  Is there a best practice concerning
when to return null and when to return an empty List? 
I see advantages to returning the empty List in that
you can can always get the iterator without checking
for null (and iterate through 0 elements when the List
is empty) or use addAll() on another List without
first checking for null.  By removing all the null
checks it seems to make the code cleaner.  However,
returning null may be a little more consistent in that
most methods that return a single result object tend
to return null if the object was not retrieved so why
would a collection be any different?  

I would love to hear your thoughts on this.

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message