This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes marker interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "marker interfaces" Watch "marker interfaces" New topic
Author

marker interfaces

Christie George
Greenhorn

Joined: Aug 16, 2004
Posts: 19
Hi

Why do designers go in for marker interfaces while designing? Whats the advantage
Vijayendra V Rao
Ranch Hand

Joined: Jul 04, 2004
Posts: 195
Marker interfaces (or tagging interfaces, as they are normally known) are basically used to "signal" something to the users of your classes. You would better understand with an example. Consider the method :



Now, this method may either recieve a LinkedList or it may recieve an ArrayList, or even some new List type that you are not even aware of! You never know with what type of a List this method will be called. However, you want to make sure that your sorter() method is as optimized as possible. How would you do this?

You might be aware that there is a tagging interface in the collections library called RandomAccess. The ArrayList implements this interface. Why? Its just to signal that random access for that particular container is going to be efficient. Random access in an ArrayList is efficient and the same on a LinkedList is definitely not. So, you can use this tag to your advantage in your sorter() method and modify the method as follows:



Does this make the concept clear?


Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

There's another thread here in javaranch
http://www.coderanch.com/t/326593/java/java/Marker-Interface
that you may readup.

ram.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: marker interfaces