IG: Unnecessary this
Just wondering, what is the difference between these two inspections?
- Unnecessary 'this' qualifier
- Unnecessary qualifier for 'this'
Without an example their descriptions are hard to differentiate.
Thanks,
Vince.
请先登录再写评论。
"Unnecessary 'this'" this is triggered when you say something like
this.foo();
or
System.out.println(this.x);
where there are no local variables named 'x' in scope. In these cases, the 'this.' is unnecesary, and can be removed.
"Unnecessary qualifier for 'this'" is triggered when you say something like
return MyClass.this;
inside class 'MyClass'. In that case, the qualifier 'MyClass.' is redundant, and can be safely removed. That's much less likely to arise in practice than the "Unnecessary 'this' qualifier" case, and is largely included for completeness. IG includes inspections for just about any sort of unnecessary redundancy, so I figured I'd include that one as well.
--Dave Griffith
Thanks. Any chance these examples could be rolled into the inspections'
respesctive descriptions? I would think I might not be the only one not to
see the difference right-away.
More generally, a lot of inspections would greatly benefit from having a
short example of what could trigger them. I realize that doing so for 500
inspections would be a daunting task. Would there be a way for people to
easily contribute examples?
Thanks,
Vince.