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.