A marker interface usually still has some contract an object must follow, even if there are no methods for enforcing that contract. By implementing the interface you are informing anyone who cares that 'Yes, I know the contract that this Marker represents and this code follows that Contract.'
My favorite example from the API is Serializable. When you look at the API you will see there is a pretty hefty contract that goes along with that interface, all designed to make sure that the instance of any class that implements the Serializable interface can be stored externally to the JVM (to a file, DB, or sent over a socket for examples). There are no methods that the Serializable interface requires, all the work needs to be done from ObjectOutputStreams, and ObjectInputStreams. But my labeling your class as Serializable you tell anyone who reads your code - and the ObjectOuputStream class, that your code can, indeed have its code stored externally following the rules that Serializable sets forth.
And note that marker interfaces were a design solution before @annotations were added to the language. You would usually want to implement this behavior with annotations, but there's no pressing reason to change pre-existing marker interfaces into annotations.
Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Joined: Sep 04, 2008
Thank you Steve for explaining the marker interface. Thank you Campbell for giving me examples of marker interface with great deatials. And Thank you Bill for providing me design level solution.