Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

marker interfaces

 
Christie George
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Why do designers go in for marker interfaces while designing? Whats the advantage
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's another thread here in javaranch
http://www.coderanch.com/t/326593/java/java/Marker-Interface
that you may readup.

ram.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic