@Nullable注释用法
本文翻译自:@Nullable annotation usage
I saw some method in java declared as: 我在Java中看到一些方法声明为:
void foo(@Nullable Object obj)
{ ... }
What's the meaning of @Nullable
here? @Nullable
在这里是什么意思? Does it mean the input could be null
? 这是否意味着输入可能为null
?
Without the annotation, the input can still be null, so I guess that's not just it? 如果没有注释,输入仍然可以为null,所以我猜不仅仅是吗?
#1楼
参考:https://stackoom.com/question/x3t2/Nullable注释用法
#2楼
It makes it clear that the method accepts null values, and that if you override the method, you should also accept null values. 它清楚地表明该方法接受空值,并且如果您覆盖该方法,则还应该接受空值。
It also serves as a hint for code analyzers like FindBugs . 它也为诸如FindBugs之类的代码分析器提供了提示。 For example, if such a method dereferences its argument without checking for null first, FindBugs will emit a warning. 例如,如果这样的方法取消引用其参数而不先检查null,则FindBugs将发出警告。
#3楼
This annotation is commonly used to eliminate NullPointerExceptions
. 此批注通常用于消除NullPointerExceptions
。 @Nullable
is often says that this parameter might be null
. @Nullable
通常说这个参数可能为null
。 Good example of such behaviour can be found in Google Guice . 可以在Google Guice中找到这种行为的一个很好的例子。 In this lightweight dependency injection framework you tell that this dependency might be null
. 在这个轻量级的依赖项注入框架中,您可以说此依赖项可能为null
。 If you would try to pass null
and without annotation the framework would refuse to do it's job. 如果您尝试传递null
且没有注释,则该框架将拒绝执行此工作。
What is more @Nullable
might be used with @NotNull
annotation. 还有更多@Nullable
可以与@NotNull
注释一起使用。 Here you can find some tips how to use them properly. 在这里,您可以找到一些如何正确使用它们的提示。 Code inspection in IntelliJ checks the annotations and helps to debug the code. IntelliJ中的代码检查可检查注释并帮助调试代码。
#4楼
Different tools may interpret the meaning of @Nullable
differently. 不同的工具可能会以不同的方式解释@Nullable
的含义。 For example, the Checker Framework and FindBugs handle @Nullable
differently . 例如, Checker Framework和FindBugs @Nullable
不同的方式处理@Nullable
。
@Nullable注释用法相关推荐
- android @nonnull的作用,@NonNull和@Nullable注释 – 它会影响Android的性能吗?
@NonNull和@Nullable注释会在运行时影响Android的性能吗?我的意思是他们只有支持LINT和其他工具来检测可能的错误的目的,所以他们可能/希望在编译期间被忽略.你有什么资料来证明这一 ...
- Java文档注释用法+JavaDoc的使用详解
Java文档注释+JavaDoc的使用详解 简介 文档注释负责描述类.接口.方法.构造器.成员属性.可以被JDK提供的工具 javadoc 所解析,自动生成一套以网页文件形式体现该程序说明文档的注释. ...
- python注释_Python的注释用法
01 单行的注释 Python的单行注释以 # 开头 # 单行的注释 print("Hello, qingnian!") 02 多行的注释 多行注释用三个单引号(''')或三个多引 ...
- spring-aop 的注释用法
一.书写增强有效代码 //切面注释 @Aspect public class errorLogger { private static Logger logger = Logger.getLogger ...
- java nullable_@Nullable和@NotNull注释的使用
本节介绍在 IntelliJ IDEA 中引入的 @Nullable 和 @NotNull 注释,IntelliJ IDEA 引用这两个注释来通过恒定条件和异常来捕获 NullPointerExcep ...
- java 类和方法自动添加注释
设置文件头File Header 路径为 setting-->editor-->File and Code Templates-->Includes-->File Header ...
- Spring注释详解
1.@Autowired注释用法 1.@Autowired 应用于构造函数(多个构造方法时必须有一个构造方法被@Autowired注释) public class MovieRecommender { ...
- 老生常谈:注释怎么写?
版权声明:本文为博主原创文章,未经博主允许不得转载. 整理自知乎上我的一次回答.http://www.zhihu.com/question/20594192 我的观点,只写说明性注释,不写功能性注释. ...
- spring boot注释_Spring Boot中的@SpringBootConfiguration注释
spring boot注释 Spring Boot中的 @SpringBootConfiguration注释是一个类级别的注释,它指示此类提供了应用程序配置. 通常,具有main()方法的类最适合此注 ...
最新文章
- 0x02 mysql 表格相关操作
- 参展神器| 算法告诉你优先参加哪个会展
- 提高代码改造过程的小想法
- PInvoke复习之深入理解char*与wchar_t*与string以及wstring之间的相互转换
- 关于Linux系统下在使用close关闭串口设备时引起的内核崩溃问题解决方法
- ORACLE数据库触发器
- Loopback Address
- hdu 3864 素数分解
- ElementUI的el-table隐藏id列
- Python笔记002-列表推导式
- 天梯—个位数统计(C语言)
- 字节一面,面试官拿System.out.println()考了我半个小时?我懵逼了...
- 二维码软件如何扫描二维码打开网页
- spring不停机部署_关于不停机部署方案的选择
- 【给量化行情插上翅膀】天翼云电脑上实践纯Python通过LMDB加速股票行情读写速度
- JAVA-win7的JDK环境变量配置安装
- 全国大学生信息安全大赛线下赛crypto3题解
- 百度人脸识别SDK的坑
- 二本学校有java校招_二本学校校招心得体会
- 关于 websocket 的 连接
热门文章
- 17、江科大stm32视频学习笔记——USART串口协议和USART串口外设
- 应届毕业生网上求职攻略
- 软件测试为什么会回归,何为“回归测试”,“回归测试”你真的理解吗?
- CTS GTS 测试记录
- c语言单源最短路径问题实验报告,数据结构课程设计最短路径问题实验报告-20210320182652.docx-原创力文档...
- 初中数学四十二个几何模型_初中数学常用几何模型及构造方法大全
- 微软开发者大会主题演讲2:微软计划扩展云计算触角
- 信息学奥赛一本通:1070:人口增长
- AndroidStudio里面导入别人的demo详细步骤
- 一个牛人给我们的建议