Can I enter a "this class" method argument?

I want to have an argument of type "this class" in the signature of the interface method, so that any class, such as MyClass that implements it, will have this method with an argument of type MyClass .

 public interface MyInterface { public thisClass myMethod(thisClass other); ... } 
 public class MyClass implements MyInterface { // has to reference this class in the implementation public MyClass myMethod(MyClass other){ ... } } 
Is this possible, or should I just bind the argument to the interface and check it for each implementation?
+4
source share
2 answers
 public interface MyInterface<T> { public T myMethod(T other); ... } public class MyClass implements MyInterface<MyClass> { // has to reference this class in the implementation public MyClass myMethod(MyClass other){ ... } } 
+3
source

This confirms somewhat that T is a class that implements the interface:

 public interface MyInterface<T extends MyInterface<T>> { public T myMethod(T other); ... } 
+3
source

All Articles