I read a lot about interfaces in java. I know you can achieve polymorphism and other great stuff (function pointers..etc). I have theoretical knowledge but pratical a little or even none. I have been using a lot of already made interfaces like "Runnable" or lots of "Listeners". But still I don't understand them 100%. If someone will answer following question maybe I will get a better understanding:
So recently I'm learning about LibGdx and I've come across Interface called "Disposable". It has one method called "dispose()" and documentation for this method says;
Releases all resources of this object.
So I assume this interface is declared like this:
public interface Disposable {
public void dispose();
}
And I have a class which implements this interface.
public class Main implements Disposable {
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
The question: How can this method do something when called if it's empty? It cannot dispose anything ..
I could have my own method in this class who would dispose objects. Why we need interface for this?
This is just an example. I've come across for a lot of similar interfaces.
I really can't understand Interfaces like this one.