Skip to content

Commit

Permalink
Update Java基础知识.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Snailclimb committed Jan 18, 2021
1 parent 9f639bf commit 348270b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/java/basis/Java基础知识.md
Original file line number Diff line number Diff line change
Expand Up @@ -1008,9 +1008,11 @@ public class Student {
#### 2.5.1. String StringBufferStringBuilder 的区别是什么? String 为什么是不可变的?
**可变性**
简单的来说:`String` 类中使用 final 关键字修饰字符数组来保存字符串,`private final char value[]`,所以`String` 对象是不可变的。
> 补充(来自[issue 675](https://github.com/Snailclimb/JavaGuide/issues/675)):在 Java 9 之后,String 类的实现改用 byte 数组存储字符串 `private final byte[] value`;
> 补充(来自[issue 675](https://github.com/Snailclimb/JavaGuide/issues/675)):在 Java 9 之后,String 、`StringBuilder` 与 `StringBuffer` 的实现改用 byte 数组存储字符串 `private final byte[] value`
而 `StringBuilder` 与 `StringBuffer` 都继承自 `AbstractStringBuilder` 类,在 `AbstractStringBuilder` 中也是使用字符数组保存字符串`char[]value` 但是没有用 `final` 关键字修饰,所以这两种对象都是可变的。
Expand Down

0 comments on commit 348270b

Please sign in to comment.