Learn from: http://blog.csdn.net/xiaanming/article/details/8703708/
http://hellosure.iteye.com/blog/1130176 content and comments are very exciting, now just learning concepts, and later in the use of the need to continue to study.
Class A implements an interface in which there is a callback method F, Class B has method Fun (), Class A object A has a reference to the Class B object B,a call B's Method Fun (), and in this method fun () calls the method F in the interface of a implementation.
In Android, the thread run method is a callback method, and the message processing in run;android is generally handled as an interface callback when start is called.
Call a method in Class B in Class A, and then call the method in Class A in the Class B d,d This method is called the callback method
Compare the classic callback methods:
- Class a implements the interface callback callback
- Class A contains a reference B to class B
- Class B has a method with a parameter of CallBack F (CallBack CallBack)
- Object A of a calls B method F (CallBack CallBack)--a class calls a method of Class B
- Then B can call a method in the F (CallBack CallBack) method--b class calls a method of Class D
PS: Encountered the doubts of the anonymous internal class, about the list with specific classes to implement the list interface, and for example, Onclicklistener, are anonymous inner class implementation, but this class does not have a name, but the implementation of the interface
Anonymous inner class:
1, the anonymous inner class is actually the shorthand format for the inner class.
2, the premise of defining an anonymous inner class: An inner class must inherit a class or implement an interface.
3, Anonymous inner class format: New parent class or interface () {Defines the contents of a subclass}
4, in fact, the anonymous inner class is an anonymous subclass object. Can be understood as an object with content.
5, it is best not to have more than 3 methods defined in an anonymous inner class.
Note: interfaces or specifications can be separated during the development process.
Java Interface callbacks