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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM