Monday 18 January 2021

Using Optional to prevent NullPointers In TrainWrecks

I don't usually post or comment on StackOverflow, but I thought I'd give it a stab.

I was thinking of using Optional.ofNullable to be able to "map" my way out of a sequence of NullPointers more or less cleanly, but I failed to get something nice.

I really like the solution give in the Answer, it's not something that would naturally occur to me.

References

StackOverflow - Using Optional to prevent NullPointers In TrainWrecks
https://stackoverflow.com/questions/65631864/using-optional-to-prevent-nullpointers-in-trainwrecks

No comments:

Post a Comment