Thursday, June 28, 2007

How Immutable Are You?

Things are subject to change. Your weight, perspective and even someone's else impression. Good things can turn to be "not-so-good" at an instant. But things are different when it comes to Java String. Thay are "Immutable". Object created by string cannot be changed. If not needed they will simply be garbage collected. I will give you an example:

String impression = "good";
String impression = "not so ".concat(impression);
System.out.println(impression);

The output will be the "not so good". But what happened to "good"? The said object are lost but the real impression was never CHANGED. :)

No comments: