Ryan said:
Is it possible to specify in an interface (or some other way) that a
class that implements it must override the toString() method of the
Object class?
No.
Interfaces have no business doing that. toString is available and does
what it does, and if it makes sense to override it, the implementor of
the class will do so. The interface exists to ensure that a given set
of operations are available on an object, and toString is always
available.
So, if you want to use the class's toString method, you can do so and it
will obey its specified behavior. If you want it to do something
different, then write a new method and have it return a String, and use
that one instead. Commandeering the toString method is very poor form
and likely to be very annoying to users of your interface, especially if
they elsewhere use toString for it's intended purpose (for example,
logging when they want to know the specific instance of an object if it
matters).
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation