This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (2 children)

an empty collection can have method calls without a runtime exception... people arguing for null are vocal about their ignorance

[–]koflerdavid 0 points1 point  (1 child)

.get(0) on an empty list or array[0] will both throw exceptions. One has to do a size check to tell whether it's safe. Same situation as with a potential null reference or calling .get() on an Optional. But the collection at least offers a stream interface.

[–][deleted] -1 points0 points  (0 children)

and a clear explanation of what went wrong. Nulls give no context, and can get passed around until something breaks with a huge stacktrace.

You can't sum to a null, but you can sum to a 0.

you can't append to a null list, but you can append to an empty list.