Effective JAVA2 reading notes-classes and Interfaces (v)

Source: Internet
Author: User
21st: Using a Function object to represent a policy

This one does not actually say anything, is the strategy mode. When you encounter this scenario, define a policy interface, and then implement it with different policy subclasses, and the main class contains a reference to the interface.

22nd: Prioritize static member classes

  A nested class refers to a class that is defined inside another class. The purpose of the nested class's existence should be to provide services only for its perimeter classes. There are four types of nested classes: Static member classes, non-static member classes, anonymous classes, and local classes. In addition to the first, three other types are called inner classes.

Sounds very round, in fact, the distinction is very simple.

First, if it is not inside the method, it is the member class (which, depending on the circumstances, should not be made static). Inside the method, that is, and there is a pre-set type that illustrates the nature of the class , which is the anonymous class. Local classes are rarely used.

Anonymous class Examples:

New Thread (new  Runnable () {        @Override        publicvoid  run () {             //  TODO auto-generated method stub                    }    });

The static inner class example is shown in the builder in article 2nd.

Effective JAVA2 reading notes-classes and Interfaces (v)

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.