specified semantics for an interface.
I'm having trouble not so much with interfaces but the way my book describes them, or more to the point. A particular point is made about interfaces.
I don't understand if interfaces are nothing more than simply declarations of methods, how can using it in whatever way you want make your code break?
Interface semantics are not enforced.
When you define a class that implements an interface, the compiler and run-time system will let you define the body of an interface method any way you want, provided you keep the method heading as it is given in the interface. However you should follow the specified semantics for an interface whenever you define a class that implements that interface; otherwise software written for that interface may not work for your class.
eg. if I create a interface called bully.
From my point of view I can't see why I can't use this interface in anyway I like, eg, I could use this BULLY as like the comparable interface. I fail to see how it would wreck my code.
public interface Bully
public boolean bullied(Object victim);
* This is pretty much just a random comment that
* has no bearing on the interface, but is assumed
* that the semantics contained within will be followed.
So long as I implement a method called bullied that takes and object and returns a boolean, it doesn't really matter how I use it does it? (well it's bad practise but my point is the code shouldn't break should it?)
Am I looking at this wrong? is there more to interfaces than is explained here?
It does go on to talk about defined constants, and pitfalls of trying to overload etc. Demos on Cloneable, Serializable, and Comparable, but this is pretty much it.