Interfaces, like classes, are also an important data type in the Java language. Variables declared with interfaces are called interface variables . So what kind of data can be stored in interface variables?
First of all, interfaces are reference variables . Interface variables can store references to instances of classes that implement the interface, that is, store references to objects.
For example: Suppose Com is an interface, then you can use Com to declare a variable.
Comcom;
Because the COM variable has not yet stored a reference to the object that implements the interface, it is said that COM at this time is an empty interface .
Assume that the ImpleCom class is a class that implements the Com interface. Use ImpleCom to create an object named object. Then the object object can not only call the original methods in the ImpleCom class, but also call the interface methods implemented by the ImpleCom class.
ImpleComobject=newImpleCom();
Origin of the term " interface callback ":
This word borrows the term pointer callback in C language, which means that the address of a variable is stored in a pointer variable at a certain moment, and then the pointer variable can indirectly operate the data stored in the variable.
In the Java language, interface callback means that the reference of an object created by a class that implements an interface can be assigned to the interface variable declared by the interface. Then the interface variable can call the interface method implemented by the class. In fact, when the interface When a variable calls an interface method implemented by a class, it notifies the corresponding object to call this method.
Note : The interface cannot call other non-interface methods in the class.