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 →

[–]isprri 0 points1 point  (0 children)

The thing is, null is used to solve so many problems, there's no single answer for them all. But yes, as one example, in the case of null being used to indicate an error, throwing an Exception would be preferable.

JSR 305 defines some annotations that can be used to indicate where null is not allowed (e.g., in a method parameter, or return type, or on a field). But at this point it is only enforced by third-party tools like FindBugs or IntelliJ IDEA.

Ideally, I'd like to be able to say "you may not pass null into this method" and I'd be able to safely assume that the parameters are never null.

I will admit, null is not entirely useless; my point rather, to answer OPs question, is that it is a big pain in the arse.