I just recently started learning Java. I have a question which is more about conventions used in Java…
So suppose I have class A:
public class A {
public void methodA{
methodB();
}
private void methodB{
}
}
Sometimes I see some people calling private methods inside the class using this (e.g. this.methodB(); ) even if there is no ambiguity. Is it convention to explicitly show people that they are invoking private method or is it just someone’s ‘style’.
In and of itself, using
thisdoes not clarify much. It can point to:this, whatever its visibility.this‘s class. (there is usually a warning in that case, but it is only a warning).What it does prevent is:
I’ll emphasize that it does not guarantee at all that the method called is private.
It is the first time I hear of this rule – I suspect that, at most, it is a (not that helpful) style rule of a company.