简体   繁体   English

eclipse kepler中的冗余空检查

[英]redundant null check in eclipse kepler

I have following line of code in eclipse kepler. 我在eclipse kepler中有以下代码行。

if (this != null) {

}

This != null show an error " Redundant null check: this expression cannot be null " even if i have changed Redundant null check into warning by going through Java > Compiler > Errors/Warnings > Null analysis . != null显示错误“ 冗余null检查:该表达式不能为null ”,即使我通过Java > 编译器 > 错误/警告 > Null分析将“ 冗余null检查 ”更改为警告。

Considering the following: 考虑以下内容:

  • The keyword this can only be used inside an instance method , ie in a method which is executed on an existing object. 关键字this只能在实例方法内部使用 ,即在现有对象上执行的方法中使用。
  • this refers to the object on which the method is called this是指在其上调用方法的对象
  • this is read-only (cannot explicitly assign null to it for example). this只读的 (例如,不能显式分配null)。
  • Calling an instance method on a null object would result in an exception. 在空对象上调用实例方法将导致异常。

Therefore, it is guaranteed that this is never null. 因此,可以保证this从来没有空。

The compiler warning helps you to identify code which makes no sense or code which is never be executed. 编译器警告可帮助您识别毫无意义的代码或永远不会执行的代码。

EDIT : About error / warning behavior of eclipse kepler, see eclipse-kepler-shows-error-marks-on-warnings 编辑 :关于eclipse kepler的错误/警告行为,请参阅eclipse-kepler-shows-error-marks-on-warnings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM