Am 26.01.2011 13:31, schrieb Ulf Zibis:

The funtionality is:
Check the argument for non-nullity AND return it if the condition holds, otherwise fail by throwing NPE.


IIRC, Object.nonNull(x) was introduced to preserve the developer from 
repetitively coding:
    if (x == null) {
        throw new NullPointerException();
    }

But isn't this not only half the rent? The 2nd part of the repetition is:
    try {
        ...
    } catch (NullPointerException npe) {
        doAlternatively();
    }

I think, in case of an expected null value, the developer has a specific idea, 
how to handle it.
Just throwing an exception should be reserved for _un_expected cases.

So something like "nullChecked(x, runnable)" could serve the full rent.
Fairly this should be delayed to closures.

-Ulf

Reply via email to