Java source code reading program (1) String class

After a blog or a little casual, as like a diary, he had just been kicked out of a big production, and ultimately chose a small company as a starting point for entering the community, and indeed skills, aspects of communicating with people are to be improved, then I will efforts, and strive to be able to go back in the future

Java source code reading program (1) String class

1.1 invariance

HashMapThe keyrecommended immutable class, hematocrit Stringvalue of this, here's immutable class refers to the color class once initialized, will not change, if modified, or it will be a new class. Next, I simply show you:

        String s = "hello";
        s = "world";

Very simple example, we look at the first line of sthe address

and then look at the second line of sthe address

we open rt.jar, then open javathe bottom of the langpackage, found Stringthe class,

where we see two final,
1. First is the class final, Stringnot is inherited, which means that all Stringthe inherited methods can not be overwritten
2. Next is to save string chararray, the same is finalmodified, that is to say valuethe array Once initialized, its memory address can not be modified, valuepermissions is private, not external access, Stringthere is no way to modify the value of open, so we can assume that valueonce they are assigned memory address can not be modified.
This is the Stringinvariance of the reason, when we want to design a class invariant time, you can mimic this style.

So most Stringof the methods, must have a return value.

Guess you like

Origin www.cnblogs.com/figsprite/p/11743962.html