Flyweight Design Model

Source: Internet
Author: User

11_dark horse programmer _ Zhang Xiaoxiang _ Java basic reinforcement _ Automatic Disassembly box for basic data and metadata-sharing design mode

 

 

 

Public static void main (string ARGs []) {

 

Integer i11 = 1;

System. Out. println (i11 + 2 );

 

Integer i12 = 1;

 

System. Out. println (i11 = i12 );

 

Integer i21 = 128;

 

Integer i22 = 128;

 

System. Out. println (i21 = i22 );

 

}

 

 

I11 is created using boxing (from the basic data type int to integer), and the first output uses automatic unpacking (from integer to int, and then addition );

The second output is true, and the third output is false. Because integer uses the metadata design mode when only one byte exists, i11 and i12 are the same memory objects (how to express them ?), After i11 creates an object, i11 objects are directly used if the same object already exists before i12 is created.

Flyweight Design Model

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.