Java 8 Optional. Why of and ofNullable?
问题 I have a question regarding Java 8's Optional, the purpose of which is to tackle NullPointerException exceptions. The question is, what is the reason for having both types to let us choose: Optional.of(T value) <-----non-null value, null value will throw NPE Optional.ofNullable(T value) <----- nullable value Because what I expect is, when I use: Optional.of(nullValue); It won't throw a NullPointerException . Expanded my question after some replies: Why would people opt for Optional instead of