This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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"