問題:
I just started using the @NotNull
annotation with Java 8 and getting some unexpected results.我剛開始在 Java 8 中使用@NotNull
註釋並得到一些意想不到的結果。
I have a method like this:我有一個這樣的方法:
public List<Found> findStuff(@NotNull List<Searching> searchingList) {
... code here ...
}
I wrote a JUnit test passing in the null value for the argument searchingList.我編寫了一個 JUnit 測試,傳入參數 searchList 的空值。 I was expecting some type of error to happen but it went through as though the annotation was not there.我原以爲會發生某種類型的錯誤,但結果好像註釋不存在一樣。 Is this expected behavior?這是預期的行爲嗎? From what I understood, this was to allow you to skip writing the boilerplate null check code.據我瞭解,這是爲了讓您跳過編寫樣板空檢查代碼。
An explanation of what exactly @NotNull is supposed to do would be greatly appreciated.對@NotNull 究竟應該做什麼的解釋將不勝感激。
解決方案:
參考一: https://en.stackoom.com/question/2J3Pr參考二: https://stackoom.com/question/2J3Pr