Callback in Android?

前端 未结 3 1191
终归单人心
终归单人心 2020-12-08 15:20

In Android application development, I frequently go through the word CallBack in many places. I want to know what it means to tell us technically - and how I ca

3条回答
  •  温柔的废话
    2020-12-08 15:55

    Hmm. How about an example. You write a quicksort algorithm in C. The user who wants to use your algorithm must supply a compare method appropriate for what the user is sorting with your algorithm. The user must pass a function pointer to the user's compare method to your quicksort code. The quicksort code uses this address, the function pointer, to CALL BACK to the user's compare function. You provide a function prototype, no implementation, since you cannot possibly know how to determine the ordinality of what is being sorted. The user supplies the implementation of compare that makes sense for what the user is sorting. This implementation must match the function prototype. The function pointer is used by the quicksort alogorithm to reach back and touch the user's code.

    This is actually about polymorphism.

    In java, you can use an interface to do this. So for sorting, see the interface IComparer and IComparable.

提交回复
热议问题