java immutable object question
Posted
by cometta
on Stack Overflow
See other posts from Stack Overflow
or by cometta
Published on 2010-03-29T01:59:56Z
Indexed on
2010/03/29
2:03 UTC
Read the original article
Hit count: 539
java
|deeper-understanding
String abc[]={"abc"};
String def[]={};
def=abc;
def[0]=def[0]+"changed";
System.out.println(abc[0]);
by changing "def" object, my abc object is changed as well. Beside String[] array has this characteristic what other java object has similar characteristic? can explain more? in order to prevent abc from changed when i changed def, i will have to do def = abc.clone();
© Stack Overflow or respective owner