I recently heard that it is possible since Java 8 to define an explicit parameter called this
in instance methods, like this:
public class Test
{
public void test(Test this, int i) { System.out.println(i); }
}
What is the use for this kind of syntax?
As you can clearly see in this screenshot (Eclipse, compiler compliance Java 8), this is valid syntax.
For Java 7 or prior, you cannot use
this
as name of a variable because it's a reserved keyword. What you can do is to passthis
as parameter into a method:For Java 8, refer to Why can we use 'this' as an instance method parameter?