An identification interface is an interface without any methods and attributes. The identification interface does not have any semantic requirements for the class that implements it, it simply indicates that the class that implements it belongs to a specific type.
There are some very famous applications in the Java language, such as the interface of the simultaneous interface, which is the identification interface. Identification interface. When a class implements an identification interface, it is like tagging itself.
To do this, we use the following three interfaces:
A SomeThing used to represent everything
public interface SomeThing {}
Human Interface:
public interface Humans extends SomeThing{}
Animal interface:
public interface Animals extends SomeThing{}
Then there are a series of implementations:
dog:
public class Dog implements Animals {}
Monster (He is very smart and tagged himself):
public class Monster implements Humans {}
The core part of the following program, Hunter and Client Program:
public class Hunter{ public void fire(Object target) { if(target instanceof Humans){ ("This is over, I've hit it"); }else{ ("Congratulations, you hit an animal!"); } } //Smart Gunpublic void intelligentFire(Object target) { if(target instanceof Humans){ return; } ("Flash!"+()); //The following is a related process such as flash sale //Destroy him target=null; } public static void main(String[] args) { Hunter hunter=new Hunter(); Object[] objects =new Object[]{new Dog(),new Japanese(),new Japanese(),new Chinese(),new Monster(),new SomeThing(){}}; for(int i=0; i<; i++){ (objects[i]); } }
I just ignore the rules you set by Hunter, and I just don't use the Humans tag. So in our program, of course, there is only the only way to get beaten.
It can be seen from this that the importance of an empty interface (label interface) is, in this example, whether to post a tag on yourself is a life-threatening issue. In fact, in the OO world, empty interfaces can be regarded as the highest layer image.