0

It is possible to manually write the receiver parameter of an instance method as below.

class A {
    public void test(A this) { }
}

Is there any purpose to write as above? Then, I tried to use it in the following way.

A a1 = new A();
A a2 = new A();
a1.test(a2);

Obviously the above is a compilation error. Why allow the user to write such syntax when it has no practical use. Is there any purpose for manually writing it?

Amrish Kumar
  • 308
  • 3
  • 12
  • Yes, the duplicate answers my question @SotiriosDelimanolis. I wonder how you find these duplicates. I clearly did a good Google search and the SO's "similar to your question suggestions" were not even close. – Amrish Kumar May 13 '20 at 21:14
  • 1
    I knew the quote from the JLS, so I looked that up directly with `site:stackoverflow.com`, which I wouldn't expect someone asking to do. But I also just tried with `java purpose of receiver parameter` on Google and the post came up as well. – Sotirios Delimanolis May 13 '20 at 21:16

0 Answers0