
6 Jul
2006
6 Jul
'06
10:23 a.m.
Martin Wille wrote:
String handling is the thing Java got basically right, IMHO. Java distinguishes between a string class (immutable strings) and a string builder class.
They had no choice but to get it right. Java is reference-based and has no const. The only way to provide value semantics is to make the values immutable. If they aren't, you have to defensively clone them whenever you are returning a field (otheriwse the caller may modify your state through its reference), which is extremely error-prone. They managed to get Date wrong, though. It's mutable.