A little discussion of Java anonymous classes and inner classes

Source: Internet
Author: User
Tags anonymous
Basic theory:
-----------------------------------------------------
About Java Inner classes: an inner class is defined as a class that is defined within another class.

The reason for this exists is:

1. An object of an internal class can access the implementation of the object that created it, including private data. That is, an internal class instance is privileged for an instance of which class contains it.

2. For other classes in the same package, the inner class can be hidden, in other words, the inner class, regardless of the visibility of the method, is even public, except for the containment class, which cannot be used by other classes.

3. Anonymous inner classes can be easily defined as callbacks.

4. The use of internal classes makes it easy to write event drivers.


In fact, its real purpose is simply to define the callback--Further, the event-driven.

Interfaces and callbacks: programming a common pattern is the callback pattern, in which you can specify a method to callback the object when a particular time occurs.



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.