• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the meaning of marker interface?  RSS feed

 
Nagacharan Lokkidi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi to all,
i knew something about marker interface i.e marker interface do not have the methods to override, but my friend said we can define our own methods. Which is the correct one my friends or me?
Please help me for this..
Thanks in advance.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marker interfaces by definition need to be empty. Else they are just like any other interface. Of course this does not mean you cannot define your own method signatures in the interface. Only that, then it wont be technically a marker interface.
More information can be found in this FAQ article http://www.coderanch.com/how-to/java/Java-FAQ#marker
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nagacharan Lokkidi wrote:
but my friend said we can define our own methods. Which is the correct one my friends or me?

We can define, but again as maneesh said we cant call that as Marker interface!
Note:marker interface contains java.lang.Object's public methods implicitly, unless you declare explicitly!
from JLS:

If an interface has no direct superinterfaces, then the interface implicitly declares a public abstract member method mm with signature ss, return type rr, and throws clause tt corresponding to each public instance method mm with signature ss, return type rr, and throws clause tt declared in Object, unless a method with the same signature, same return type, and a compatible throws clause is explicitly declared by the interface.


<edit>for clarity</edit>
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please avail yourself of the search facility of this site to find the many, many, threads where this subject has been asked and exhaustively answered before. There's no really no point in rehashing all that over and over and over again.
 
sekhar kiran
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am looking for marker interface details.actually i know it has no methods eg serializable,cloneable and single thread model.recently i faced a interview question ie if serializable is a marker interface means then why it has two methods writeExternal and readExternal.what is the use of marker interface,simple explanation will be helpful to me.iam so confused
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sekhar kiran wrote:if serializable is a marker interface means then why it has two methods writeExternal and readExternal.

This is wrong - it does not have any methods, as you can see in the API documentation: java.io.Serializable

Interface java.io.Externalizable does have those two methods, but that's not a marker interface.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!