Assume that there is a class like the following.
public Class SomeClass {
private A getA() {
...
}
public void show() {
A a = getA(); // CASE #1
...
}
public void show2() {
A a = this.getA(); // CASE #2
...
}
Their result are same, isn’t? My idiot co-worker insisted that’s right!!(it means they’re different.)
They’re the same in this context. I’d advocate not using
thissince it’s implied and it’s just cluttering up the code by being there, but it makes no practical difference whether it’s there or not.It’s not useless though. The
thiskeyword is required sometimes, for instance:<String, String>stringMethod(), it has to bethis.<String, String>stringMethod().That’s by no means an exhaustive list, just serves as an example to demonstrate while it doesn’t make a difference in this case, it can do in other cases!