public String(String original) {
this.value = original.value;
this.hash = original.hash;
}
我不明白原始是如何转换为char数组的。如果我尝试使用其他代码,则会引发编译错误。
最佳答案
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
因为您位于
String
的构造函数中,所以您有权访问其专用字段value[]
和hash
。您无法从String类外部访问这些
private
字段,因此,如果尝试执行此操作,则会引发编译错误。