本文介紹了@Nullable 注解用法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我看到java中的一些方法聲明為:
I saw some method in java declared as:
void foo(@Nullable Object obj)
{ ... }
這里的@Nullable
是什么意思?這是否意味著輸入可能是null
?
What's the meaning of @Nullable
here? Does it mean the input could be null
?
沒有注解,輸入仍然可以為空,所以我猜不只是它?
Without the annotation, the input can still be null, so I guess that's not just it?
推薦答案
明確了方法接受空值,如果你重寫了方法,你也應該接受空值.
It makes it clear that the method accepts null values, and that if you override the method, you should also accept null values.
它還可以作為 FindBugs 等代碼分析器的提示.例如,如果此類方法取消引用其參數而不首先檢查 null,則 FindBugs 將發出警告.
It also serves as a hint for code analyzers like FindBugs. For example, if such a method dereferences its argument without checking for null first, FindBugs will emit a warning.
這篇關于@Nullable 注解用法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!