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;