Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

Is an empty interface (without any methods) is marker?

 
Ranch Hand
Posts: 45
Google Web Toolkit Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I was having this discussion with my friend regarding Marker interface.

Where a generalize statement is "Interface without any method is Marker interface". We were discussing up to what extent it is correct.

Argument : Interface without any method is Marker interface.
Counter Argument : What if the code using particular interface is not using it as marker purpose.
Support statemetns :
Case : 1) Interface is having constants and no methods.
Case : 2) There is an interface 'I' without any methods, but no one is implementing that interface. Is it still Marker interface?
Case : 3) Serializable is marker interface, after only the code using serializable object to converts it in to bytes.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is more about how it is used than whether it defines constants or not. eg java.io.Serializable and java.lang.Cloneable indicate that the marked classes will be able to take advantage of special code for serializing and cloning.
If you don't use serialization or cloning then whether it is a marker interface or not doesn't concern you.

Similarly if I create an interface with no methods and no constants but there is no code to use it as a marker then it looks like a marker but does nothing.
 
reply
    Bookmark Topic Watch Topic
  • New Topic