• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is exactly stands for Marked interface?  RSS feed

 
Sirish Reddy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all JavaGuys,
Here my query is abt Marked interface in my point of view it is noting but a interface which has no methods.This is the only correct answere or is their any reason to say it is marked interface?
Thanking you,
Cheers..
Sirish G Reddy.,
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Marked interface"? I think I understand you, but correct me if I'm wrong: I assume you are talking about an interface like java.io.Serializable, which is an interface which defines no functionalitly? In this case it is just a marker. Suppose you have a bunch of classes, all which extend the same base class. They will have the same common functionality and base type. Then suppose you need to start using only some of these objects for a particular type of functionality (in Serializable's case, the ability to marshall and unmarshall the object for persistance or remote communication). You need a way to know which objects can behave like this so you mark them by making them implement the Serializable interface.
 
Sean Stephens
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you are talking about a "Marker" interface. As Paul said, its an interface used to "mark" an object. Serializable is an example in the actual java jdk. Marker interfaces have no methods or fields. Typically it would go something like this

Say you have 2 marker interfaces named Blue and Red. You also have a class named MyObject and 2 subclasses of that, MySubObject implements Blue, MyOtherObject implements Red.

You have some method that needs to do something to MyObject, but only after something is done to it if its Red or Blue.

for example:

MyObject myO = getMyObject();

if (myO instanceof Red) {
myO.doBlueShift(); // doBlueShift method defined on MyObject
} else if (myO instanceOf Blue) {
myO.doRedShift(); // doRedShift also defined on MyObject
}

myO.doStuff(); // this action is done on all MyObjects




Hope that helps,
Sean
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java in General (intermediate)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!