Java Closures and callbacks

Source: Internet
Author: User
Tags closure

Closures are also called lexical closures

Closures are first defined as an entity that contains < environment components > and < control Components > .

Explanation: A closure is a function that references a free variable, and the referenced variable will exist with the function.

EXPLANATION Two: Closures are entities that comprise functions and related reference environments.

Note:< free variable >: Other variables except local variables

Simple to understand: a closure can store a method as a variable that has the ability to access the free variables of the class in which it is located.

Java closure mechanism, its implementation requires two partial closure class (temporary salutation) + interface. Closure class: It is an object that can be called. It contains the contents of some scopes (which can be arguments, methods), and it automatically has a reference to an external class that accesses the private members of the external class.

The closure mechanism can solve the problem of doing different operations with the same method.

Callback: In short, A is called B to do one thing and tell him to inform after the completion of the notice, specifically how to inform a decision, the operation or method of this notice is the callback method

Java Closures and 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.