4 ms·
How is boxed null possible? The documentation for Optional.of(T value) says that it'll throw NullPointerException if value == null. https://docs.oracle.com/java
by nayuki 4y ago
How is boxed null possible? The documentation for Optional.of(T value) says that it'll throw NullPointerException if value == null. https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#of-T- https://docs.oracle.com/javase/8/docs/api/java/util/Optional...
- vanjajaja1 4y agoThat's because Optional.of(null) == Optional.empty() Optional.empty() is boxed null
- conro1108 4y agoOptional.of(null) throws a NullPointerException ;) Optional.ofNullable(null) == Optional.empty()
- vanjajaja1 4y agoI'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.