读书人

java String类的源码的疑问解决方案

发布时间: 2012-02-11 09:51:35 作者: rapoo

java String类的源码的疑问
public String(String original) {
int size = original.count;
char[] originalValue = original.value;
char[] v;
if (originalValue.length > size) {
// The array representing the String is bigger than the new
// String itself. Perhaps this constructor is being called
// in order to trim the baggage, so make a copy of the array.
int off = original.offset;
v = Arrays.copyOfRange(originalValue, off, off+size);
} else {
// The array representing the String is the same
// size as the String, so no point in making a copy.
v = originalValue;
}
this.offset = 0;
this.count = size;
this.value = v;
}

这段是java的String类源码中的一个构造函数,应该怎么理解。那个original是怎么回事,还有那个count是在哪被始化的?

[解决办法]
一起看看这个 JAVA String对象和字符串常量的关系解析 .
共同学习下~~~~ 原来堆 栈的问题有看了理解一些,久了不看又忘了哪个是哪个了

读书人网 >J2SE开发

热点推荐