A tagging interface is one which consists of a name only, and has no methods. This question seems to come up regularly; I thought there was a thread about it about one week ago, but can't seem to find it. Try the search yourself, see if you can't do better than I did.

There is considerable controversy about whether tagging interfaces ought to be allowed at all, but there are several which are in the API in common use, eg java.io.Serializable and java.rmi.Remote, and it would be impossible to get rid of them. I think there are about three more. Lots of people advise against users writing their own tagging interfaces.

If you are going to write a tagging interface you would have to have a method which requires it. Now that is a very trivial example, showing what you would have to do to use a tagging interface. More to the point, it shows what a useless exercise it would be. All you have achieved is an extra "layer" of complexity in the coding.

You can't implement the methods in a tagging interface because it hasn't got any methods to implement.

Campbell is quite right, the question comes up regularly, though more often under the moniker "marker interfaces". The Java Intermediate FAQ has a section on the topic. [ June 13, 2006: Message edited by: Ulf Dittmer ]

Campbell Ritchie

Marshal

Posts: 57443

175

posted 11 years ago

Thank you, Ulf Dittmer. No wonder I couldn't find it; I couldn't remember the other name. The thread I was looking for, which has links to the FAQ, is here.

They have to implement it because that is the nature of the interface. It is by default the essence of the functionality of your program. When you have your "skeleton" signatures up in your interface you will have to use the exact same signature in your method that the interface implements. This method will make it "concrete" and actually do something.

If your question is really to put in some sort of trip code to actually FORCE someone to implement the interface then I don't know of one. It just makes it easier.

megha ghanekar

Greenhorn

Posts: 17

posted 11 years ago

Hi Gabriel, I was talking @ my own tagging interface. And i want to force the users to implement that. I forgot to mention the tagging word.

Warm regards, meghana

Gabriel White

Ranch Hand

Posts: 233

posted 11 years ago

A tagging interface is one which consists of a name only, and has no methods.

Seriously what could the point of this possibly be? I can sort of see what it could be used for but what lesson does it teach?

Ulf Dittmer

Rancher

Posts: 42975

76

posted 11 years ago

Seriously what could the point of this possibly be?

Follow the link posted by Campbell; it contains some more in-depth discussion and further links.

Campbell Ritchie

Marshal

Posts: 57443

175

posted 11 years ago

There is a way you could force somebody to implement the interface. You have a method which requires an object of the tagging interface as its parameter. I have already posted a potential example as my first posting on this thread. I have also (as Ulf Dittmer has pointed out) quoted links to other discussion on the same topic, and given an opinion about how useful such an action would be.

Another way is to have a statement in the method throwing an exception if you don't use the interface:-Again, what is the point, except as a training exercise?