字符串不可变的条件

在String源码中有如下代码:
  /** The value is used for character storage. */
  private final char value[];
 
  /** Cache the hash code for the string */
  private int hash; // Default to 0这就导致了每次生成的字符串不可变动。每次变动都是生成新的数组;再来一次深拷贝;
字符串不可变
阅读 38
2022-01-15
字符串不可变的条件

在String源码中有如下代码:
  /** The value is used for character storage. */
  private final char value[];
 
  /** Cache the hash code for the string */
  private int hash; // Default to 0这就导致了每次生成的字符串不可变动。每次变动都是生成新的数组;再来一次深拷贝;
相关推荐
精彩评论(0)