Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
vanjajaja1
· 3y ago · 0 comments
That's because Optional.of(null) == Optional.empty() Optional.empty() is boxed null
Comments
[–]
conro1108
3y ago
Optional.of(null) throws a NullPointerException ;)
Optional.ofNullable(null) == Optional.empty()
[–]
vanjajaja1
OP
3y ago
I'm trying to say that .of(null) and .empty() semantically the same, which is why it throws NPE to force explicit empty. ofNullable is a whole other kettle of fish.