[英]How String class in initiated with constructor java
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
字段,因此,如果尝试执行此操作,则会引发编译错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.