If you have a method similar to the following:
public void setFoo(Foo foo) { this.foo = foo; }
Using this is a must. Otherwise, it assigns the argument foo to itself, and does not assign it to the instance variable.
But this does not mean that the only situation in which you can use this . The following code is strictly equivalent:
public void setFoo(Foo newFoo) { this.foo = newFoo; }
Although in this case you can write
public void setFoo(Foo newFoo) { foo = newFoo; }
because this no longer required . This does not make it illegal .
So,
int getValue() { return time * 5; }
and
int getValue() { return this.time * 5; }
strictly equivalent.
source share