I recall the first oddity that struck me about Java programming is that it seems common practice to test returned objects for null. I find it frustrating and inefficient to scatter if conditions throughout my code just to see if I have a valid object instance returned.
Receiving null is confusing. When you make a function call and the result is null what does it mean? Was the data not found? Was there an exception in the function that was silently swallowed resulting in the return of a null object? You're not really sure if null is an expected return value. If no exception is thrown then you just kind of assume that null is a valid return value. However, you can't really do anything with the returned null object so what do you do now?
Here are a couple of alternatives to returning null:
Home
Community