javax.annotation中:@Nullable VS @CheckForNull [英] javax.annotation: @Nullable vs @CheckForNull

查看:5997
本文介绍了javax.annotation中:@Nullable VS @CheckForNull的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者有什么区别?似乎都意味着该值可能为空,并应与相应即检查空处理。

What is the difference between the two? Both seem to mean that the value may be null and should be dealt with accordingly i.e. checked for null.

更新:
上述两个注解是JSR-305 / FindBugs的一部分:
<一href=\"http://findbugs.sourceforge.net/manual/annotations.html\">http://findbugs.sourceforge.net/manual/annotations.html

推荐答案

我觉得这是pretty从您添加的链接清楚:如果你使用 @CheckForNull 和使用该值code不检查,FindBugs的将其显示为错误。

I think it is pretty clear from the link you added: if you use @CheckForNull and the code that uses the value does not check for null, FindBugs will show it as an error.

FindBugs的会忽略 @Nullable

FindBugs will ignore @Nullable.

在实践中,这批注仅用于覆盖一个总体是非常有用的非空注释。

In practice this annotation is useful only for overriding an overarching NonNull annotation.

使用 @CheckForNull 的情况下,当值必须始终进行检查。使用 @Nullable ,其中可能确定。

Use @CheckForNull in the cases when the value must always be checked. Use @Nullable where null might be OK.

编辑:看来, @CheckForNull 不是此刻很好的支持,所以我建议避免它,并使用 @NonNull (另见 @NotNull Java注释我应该使用哪个?)。
另一个想法是接触与FindBugs的开发人员能够直接,询问文档中的不一致的意见。

it seems that @CheckForNull is not well supported at the moment, so I suggest avoiding it and using @NonNull (also see Which @NotNull Java annotation should I use?). Another idea would be to get in touch directly with the FindBugs developers, and ask their opinion about the inconsistency in the documentation.

这篇关于javax.annotation中:@Nullable VS @CheckForNull的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆