Java Interface callbacks

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.