Java Invariant class

Source: Internet
Author: User

<title>Java Invariant class</title> Date: December 28, 2015 11:18:33
Definition: A class that does not change, that is, a class that does not change when an instance of the class is created.
For example, a wrapper class such as String Integer Boolean
The benefits of invariant classes: 1. Thread-safe, because the state of the invariant class does not change after it is created, data sharing between threads is possible, and no synchronization is required. 2. Instance of immutable classes can be reused (reuse).
if a class is invariant, does this class have a way of changing the state? The answer, of course, is no, string is a invariant class, there is still a way to Replace,replaceall, and string is still a constant class, because in these methods of changing state, each time a new string object is created.



From for notes (Wiz)

Java Invariant class

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.