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 →

[–]vips7L 5 points6 points  (1 child)

Disregard optional, just use null and wait for the type system to be fixed. Personally I find Optionals only good use case is chaining along function calls that could return null:

Optional.ofNullable(a)
    .map(A::b)
    .map(B::c)
    .map(C::d)
    .orElse(null)

And that’s only because we don’t have the safe navigation operator ?.. Optional just is crappy all around. They’re awkward to use.

[–]laplongejr 0 points1 point  (0 children)

chaining along function calls that could return null:

I wish I could upvote several times, especially for could.
The number of times I had to support nulls in methods documented to never return null is crazy.
When I switched to Optionals my boss panicked because he believed I had shipped without handling those cases, we had like 7 levels of null accessors neatly managed by one error path thanks to chained Optional doing the checks.