java - eclipse GetAnnotation 返回@NonNull
问题描述
我正在尝试使用 Eclipseorg.eclipse.jdt.annotation.NonNull
注释,但我不明白这一点
方法签名:
@NonNull MyAnnotation java.lang.reflect.Field.getAnnotation(Class<@NonNull MyAnnotation> annotationClass)
for loop:
if(field.getAnnotation(MyAnnotation.class)!=null)
continue;
Eclipse 声明如下代码 死代码
try{
为什么 eclipse 认为getAnnotation
该类返回@NonNull
?文档清楚地说明它可以返回null
。
我已经通过调试器验证了代码没有死,踩低谷。
编辑: 我不在任何包上使用 @NonNullByDefault
我试过了:
- 添加
@Nullable
到 MyAnnotation,我得到The nullness annotation 'Nullable' is not applicable at this location
@Nullable MyAnnotation n=field.getAnnotation(MyAnnotation.class);
还是一样的问题
解决方案
通过添加第一行来消除警告:
Class<MyAnnotation> c = MyAnnotation.class;
if(field.getAnnotation(c)!=null)
continue;
之后我没有收到死代码警告。
不知何故,Eclipse 将 @NonNull 注释自动添加到 MyAnnotation。
推荐阅读
- python - 如何以这种特定方式按日期对 Pandas DataFrame 进行排序?
- regex - 在 Rasa NLU 中使用正则表达式和实体
- asp.net-core - 将我的复选框更改为我的 asp.net 核心 mvc 中的 2 个单选按钮(是和否)
- python - 使用 Python 在 Vercel 中将多个路由组合成一个无服务器函数?
- server - 无法在 BlackBox 中启动服务器
- javascript - 如何从数组中计算对象 - javascript
- python - 如何提取纸浆中的CBC经过时间?
- mod-wsgi - 使用 pyenv 的 mod_wsgi 共享库超过 1MB
- python - 如何在python中使用tika解析器提取每页超过2000个字符的pdf页面?
- elm - 使用多个构造函数更新 Elm 记录