If I have a class which has an interface definition like below;
public class FirstClass {
private static onDragListener listener
public interface onDragListener{
void doSomething();
}
//a static method to set on my drag listener
public static void setOnDragListener(onDragListener listener){
FirstClass.listener = listener
}
}
As you see above, there is a setOnDragListener(onDragListener listener) static method to set on the listener.
Then, there is another class which implements the interface defined in the first class like below:
public class SecondClass implements onDragListener{
public void initialize(){
FirstClass.setOnDragListener(this); //my question is here about 'this'.
}
}
My question is why I can use this as the argument pass to the FirstClass.setOnDragListener(this); in the initialize() method above?
I mean the setOnDragListener(onDragListener listener) is expecting a onDragListener type argument to pass in, does this in the initialize method of second class means the real implementation of the interface or how can I understand it?
Inheritance is a
is-arelationship.SecondClassis-aonDragListener.thisis aSecondClass.Ergo,
thisis aonDragListener.