participate


New To Java - Use of Marker Interface [Locked]
This topic is locked
<<   Back to Forum  |   Give us Feedback
This topic has 18 replies on 2 pages.    1 | 2 | Next »
BandaruNarendraBabu
Posts:60
Registered: 9/15/04
Use of Marker Interface   
Feb 16, 2005 1:33 PM

 
Hi,

Please explain what is the use of Marker interface like cloneable, serilizable ..
This interfaces are empty interfaces.

Why we need Marker interfaces ???

Please let me know your valuable views...
 
filestream
Posts:6,287
Registered: 3/22/04
Re: Use of Marker Interface   
Feb 16, 2005 1:40 PM (reply 1 of 18)  (In reply to original post )

 
To let the system know that some action can be formed on a class that implements the marker?

Serializable --> class be serialized
etc.
 
YATArchivist
Posts:4,906
Registered: 23/07/02
Re: Use of Marker Interface   
Feb 16, 2005 4:00 PM (reply 2 of 18)  (In reply to original post )

 
Arguably we don't, except for backwards compatibility, because of annotations.
 
Digbijoy
Posts:1
Registered: 4/25/05
Re: Use of Marker Interface   
Apr 25, 2005 4:46 AM (reply 3 of 18)  (In reply to original post )

 
Hi,

The marker interface is just an identity which defines whether the class can able to perform certain specified actions.

Eg:

class TestCloanble implements Cloneable {

}

So classes that implements Cloneable (See above Eg:) can be copied using the clone() method.

Thx
Digbijoy Das.
 
ProggerFromKupfer
Posts:93
Registered: 4/22/05
Re: Use of Marker Interface   
Apr 25, 2005 4:53 AM (reply 4 of 18)  (In reply to original post )

 
But marker interfaces is rather a design antipattern than a design pattern, so Clonable & Co. shouldn't be emulated (see J. Bloch, Effective Java). It needs a lot of extra documentation to explain what such an interface is good for.
 
freddi
Posts:196
Registered: 6/24/97
Re: Use of Marker Interface   
Apr 25, 2005 5:07 AM (reply 5 of 18)  (In reply to original post )

 
Marker interfaces are used to specify that a class belongs to a logical family or grouping - as quoted above, Cloneable is used to indicate that a particular class can be cloned, or Serializable is used to indicate that a particular class can be serialized.

IMHO, it is very rare that Marker interfaces are an intenional result of good design. In both the above cases, the relevent clone() and serialize() methods could have been moved out of the Object class into the relevent interface - and these would no longer be marker interfaces.
 
venkatneelam
Posts:1
Registered: 7/8/05
Re: Use of Marker Interface   
Jul 8, 2005 8:07 AM (reply 6 of 18)  (In reply to #5 )

 
can i know what is the use of marker interface.
if any body can reply for this i am very happy.
regards.
venkat.n
 
Athena
Posts:701
Registered: 6/29/05
Re: Use of Marker Interface   
Jul 8, 2005 8:10 AM (reply 7 of 18)  (In reply to #6 )

 
can i know what is the use of marker interface.
if any body can reply for this i am very happy.

Read the replies above your head.
 
BIJ001
Posts:6,896
Registered: 2003.06.06.
Re: Use of Marker Interface   
Jul 8, 2005 8:13 AM (reply 8 of 18)  (In reply to #6 )

 
Whether a class is declared to implement a given (empty, merker) interface or not is a bit of information. It can be used to mark something about the class on the meta-level, that is, not on the direct level of interfcae method availability.

One can argue whether the Cloneable and Serializable are good usage or not.
(Arguably Cloneable not, Serializable yes).
 
kybernetikos
Posts:1
Registered: 10/31/05
Re: Use of Marker Interface   
Oct 31, 2005 7:20 AM (reply 9 of 18)  (In reply to #8 )

 
If you read the Effective Java chapter on serialization, you may begin to question that Serializable is a good use of a marker interface. One of the annoying problems with marker interfaces is that you can't remove them in subclasses, yet for functionality that is independant of the natural is-a relationship and is used entirely in tangential service code, it would make sense to. Almost every use of a marker interface causes problems. The closest I would choose to a correct one would be RandomAccess. Collections are generally RandomAccess or not, and the Abstract class can make very sensible decisions about the best way to do things based on whether or not its subclasses are RandomAccess or not. Of course, you still have the problem that you can't subclass RandomAccess classes and make them not RandomAccess, but this would be quite unusual subclassing behaviour anyway.
 
Sreejipnr
Posts:9
Registered: 12/11/06
Re: Use of Marker Interface   
Dec 11, 2006 12:58 AM (reply 10 of 18)  (In reply to #9 )

 
Hi,

Can we define our own marker interface?
If yes. How to do the same?

Thanks in advance.

Sreejith-
 
cotton.m
Posts:15,338
Registered: 8/26/05
Re: Use of Marker Interface   
Dec 11, 2006 12:59 AM (reply 11 of 18)  (In reply to #10 )

 
Hi,

Can we define our own marker interface?
If yes. How to do the same?

Thanks in advance.

Sreejith-

public abstract interface Sreejipnr{
 
}


There you go.
 
georgemc
Posts:16,778
Registered: 5/8/06
Re: Use of Marker Interface   
Dec 11, 2006 4:16 AM (reply 12 of 18)  (In reply to original post )

 
so you can give various classes a common supertype, basically
 
m_k_m
Posts:7
Registered: 5/21/07
Re: Use of Marker Interface   
May 21, 2007 4:15 AM (reply 13 of 18)  (In reply to #12 )

 
Can any body tell how marker interface is handled by JVM?? thanks in advance.
 
georgemc
Posts:16,778
Registered: 5/8/06
Re: Use of Marker Interface   
May 21, 2007 4:53 AM (reply 14 of 18)  (In reply to #13 )

 
Can any body tell how marker interface is handled by
JVM?? thanks in advance.

Same way as any other class or interface. The marking is for the convenience of other Java code
 
This topic has 18 replies on 2 pages.    1 | 2 | Next »
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 24
  • Guests : 134

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums