|
最初由 muzi2005888 发布
[B]我想问个,就是关于
string tr="abc";
string tr=new string("abc" ;
有什么不同? [/B]
1 .string tr="abc";存于常量内存区
2.string tr1=new string("abc" ; 存于堆栈中
第一个是一个对象,第二个2个对象产生
tr==tr1 结果是false的
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.
v = new char[size];
System.arraycopy(originalValue, original.offset, v, 0, 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;
}
"abc"作为参数是一个String对象,而tr1是它的一个copy,第二个String对象,所以答案是两个String对象产生 |
|