I've read about interfaces in Java and now I want to make an interface which allows me to create the construction like below:
public class MyClass implements View.OnTouchListener {
//Implementation
public boolean onTouch(View arg0, MotionEvent arg1) {
/*SOME CODE*/
return true;
}
}
So I want to create similar interface (class). How can I invoke onTouch method from OnTouchListener interface if I don't know which class implements it? And how can I know which classes implements this interface if I decided to separate classes from interface (different libraries)? Hope you understand what I mean.
Thanks a lot!
I feel like I understand part of your question.
using a setup like
the instanceof reserve word will tell you if the given object is an instance of that class--whether it be through inheritance or implementation
David B. answered the first half of your question--call the onTouch(arg0, arg1) on the object itself.
Just saw your edit--if you use the instanceof keyword, you can check if the given object implements the interface (which means it would have the onTouch method). See the above code block for such an implementation.