Spring @Nullable
Spring提供的 编译期(Idea\Eclipse编译时检查,需设置开启) Null-safety检查
@Nullable
:字段可以为空@NonNull
:字段不能为空@NonNullApi
: 包级别,参数和返回值非null@NonNullFields
:包级别,字段默认非空
package-info.java 放在需检查的包路径下
/**
* Provides basic classes for exception handling and version detection,
* and other core helpers that are not specific to any part of the framework.
*/
@NonNullApi //所有参数和返回值非null;如有字段需设置可为空,使用@Nullable
@NonNullFields
package org.springframework.core; //检查org.springframework.core包下的所有字段
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;