Possible Duplicate:
Why is String final in Java?
There are various moments in my programming life that I wished the the String class had not been final/sealed/NotInheritable.
What are the language architects trying to prevent me from doing that would throw a monkey wrench into the works.
Rather, what are the monkey wrenches the language architects would want to prevent me from throwing into the works by restricting me from extending String class?
Could you list a list of pros-cons of extendable string class?
String is an immutable class which means if you cannot modify its state after you create it. If you could modify a string after it has entered another library, or a Map for instance the result would be unpredictable.
One mistake of the Java API is that
BigIntegerandBigDecimalare not final which means you need to perform a defensive copy of these objects when receiving them from non trusted code. Conversely, you can always trust that aStringwill remain consistent.Untrustworthy BigInteger:
The same thing is not possible with
String. As stated in Effective Java, you need to make defensive copies of these types of objects: