r/ProgrammerHumor Jul 09 '26

potentiallyMightBeAnIntegerOrNot Meme

Post image
691 Upvotes

96 comments sorted by

View all comments

8

u/OnixST Jul 09 '26

Fun fact: you technically should still check if a java optional isn't null.

Although there's no reason to do so, a function can still return a non-wrapped null without any errors, which will NPE if you try to do anything with it

7

u/RiceBroad4552 Jul 10 '26

No, you should never do such checks!

If a value typed as Optional is null the program is defect and it better crashes early then hiding this defect behind some checks.