Optional require(s) NonNull

Boaz Nahum boaznahum at gmail.com
Mon Oct 29 08:02:51 PDT 2012

I thought I understand Optional till I read the implementation:

public Optional(T value) {
        this.value = Objects.requireNonNull(value);
        this.present = true;

Why 'requireNonNull' non null ? If null is singular value why we need this
class ? just for 'orElse..' methods ?

If if value can't be null why we need the 'present' field ?

My hopes where that I can use Optional to return a null as a legal value.


More information about the lambda-dev mailing list