Java 8 Optional. Why of and ofNullable?

后端 未结 8 1519
旧时难觅i
旧时难觅i 2021-02-07 01:01

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 h

8条回答
  •  别那么骄傲
    2021-02-07 01:52

    I think the main purpose is that using Optional.of() can throw null-pointer which is exactly what we need in some cases.

提交回复
热议问题