Design Mode-Metadata Mode

Source: Internet
Author: User

In boxing, Flyweight refers to the most lightweight model, that is, "Fly magnitude" or "rainfall level". Here we use the free translation of "Enjoy yuan mode", because it can better reflect the intention of the model. The metadata mode is the object structure mode. The metadata mode supports a large number of fine-grained objects efficiently in a shared manner.String type in Java

In JAVA, the String type uses the metadata mode. The String object is of the final type and cannot be changed once it is created. In JAVA, string constants exist in the constant pool. JAVA ensures that a String constant has only one copy in the constant pool. String a = "abc", where "abc" is a String constant.

Public classTest {public static voidMain (String [] args) {String a = "abc"; String B = "abc"; System. out. println (a =B );}}

In the above example, the result is true, which indicates that both references a and B point to the same String constant "abc" in the constant pool ". This design avoids unnecessary resource consumption when creating N multiple identical objects.

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.