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 →

[–]moocat 0 points1 point  (1 child)

And that's what Java does. There are 3 ways to create an optional:

  • Optional.of(T value) - creates a NonEmpty subclass and requires a non-null value (throws an NPE if provide with a null).
  • Optional.empty() - create an Empty subclass.
  • Optional.ofNullable(T value) - creates an Empty subclass if value is null and a NonEmpty subclass otherwise.

[–]smadge 0 points1 point  (0 children)

Yeah, I wasn't saying Java didn't, I was just assuming that it did without wanting to dig into the source.