Why is the string class final

Source: Internet
Author: User

First we use new to create a string object, such as:

String Str=new string ("123");

In this sentence, two objects were created, and the first one created a string "ABC" in the system;

Then in the creation of a Str object, and then in Let "123" of this string reference;

Creating a String object is equivalent to creating two.

Talk about why the string class is set to the final type.

The fianl type is a type that cannot be modified.

Imagine if I was right

Str=str.touppercase ();

Why does this need to be returned instead of being changed directly?

First, if the direct change may be manipulated to the system created by the ABC string, when the new ' ABC ' object, the system will no longer create an ABC object, but the newly created object directly to the ' ABC ' string

Failure to set the final type causes a direct operating system string that causes problems with the system string:

Why is the string class final

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.