问题:
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