Why should one use Objects.requireNonNull()?

前端 未结 11 1801
谎友^
谎友^ 2020-12-02 04:06

I have noted that many Java 8 methods in Oracle JDK use Objects.requireNonNull(), which internally throws NullPointerException if the given object

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 05:05

    The basic usage is checking and throwing NullPointerException immediately.

    One better alternative (shortcut) to cater to the same requirement is @NonNull annotation by lombok.

提交回复
热议问题