• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About Interface

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
Well i just want to ask that what is the purpose of "marker interface"?
And if it does'nt have body then how it applies default behaviour?
please clear my doubt.
Thanks.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And there's a bit more in one of these FAQ.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic