在方法参数中使用 NotNull Annotation - Using NotNull Annotation in method argument

问题:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章