Understanding of the Java callback interface

Source: Internet
Author: User

Class A holds the object reference of the B interface, the B interface has a callback () method, the Class C is an implementation class of Class B, implements the callback () method, passes the class C into Class A, and when class A executes the operation calls the callback () method, then a calls the Class C callback ( ) method, which is equivalent to notifying C "My operation is complete," we just write the callback () method in Class C, which is the callback. Understanding is not difficult, write more can be!

1  Public InterfaceB {2      Public voidcllback (String result);3 }4  Public classCImplementsb{5  6      Public voidcllback (String result) {7         //TODO auto-generated Method Stub8         if(Result.equals ("Operation completed")) {9System.out.println ("I am c, received a notice, A has finished work");Ten         } One     } A       - } -  Public classA { the B OBJECTB; -      Public voidSETOBJECTB (B objectb) { -          This. OBJECTB =OBJECTB; -     } +      Public voidoperation () { -         /* + * Business Operations A * Business Operations at          * */ -Objectb.cllback ("Operation Complete"); -     } - } -  Public classMain { -      Public Static voidMain (string[] args) { in         //TODO auto-generated Method Stub -A Objecta=NewA (); toOBJECTA.SETOBJECTB (NewC ()); + objecta.operation (); -     } the   *}

Understanding of the Java callback interface

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.