Reputation: 9
I have following line of code in 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.
Upvotes: 0
Views: 1389
Reputation: 7773
Considering the following:
this
can only be used inside an instance method, i.e. in a method which is executed on an existing object. this
refers to the object on which the method is calledthis
is read-only (cannot explicitly assign null to it for example). Therefore, it is guaranteed that this
is never null.
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
Upvotes: 3