Learning Java, I have never used the keyword "this". So I am wondering when it is smart to use it. I know that it does prevent name conflicts:
public class test
{
int x;
int y;
public test(int x, int y)
{
this.x = x;
this.y = y;
}
}
But this code can instead, and, I think, better, be written like this:
public class test
{
int x;
int y;
public test(int a, int b)
{
x = a;
y = b;
}
}
So, could someone please explain to me when it is smart and/or necessary to use "this" in Java?