this
refers to the instance you are presently in. So it is checking to see if for example, p.next
is not the same instance via p.next != this
Here is an example to demonstrate the concept.
Foo foo1 = new Foo();
Foo foo2 = new Foo();
System.out.println(foo1);
foo1.printInstance(foo1); // should be the same.
System.out.println(foo2);
foo1.printInstance(foo2);
public class Foo {
public void printInstance(Foo foo) {
System.out.println(this);
System.out.println(this == foo ? "Equal" : "Not equal");
}
}
Prints something similar to the following:
Foo@7a81197d
Foo@7a81197d
Equal
Foo@5ca881b5
Foo@7a81197d
Not equal