String is final... for good reason. There are a lot of optimizations happening behind the scenes for String objects (pooling etc.) that extending String could do great harm. Either way, if you are in need to extend String, you might want to rethink your design approach.
JDBCSupport - An easy to use, light-weight JDBC framework -
Sorry, but the final keyword will prevent you from doing so. You could create a class that implements all of the interfaces and class methods of String, but that seems like a lot of work. Another option would be to create your MyString class as a wrapper class for String, with pass-through methods for String's class and interface methods. None of this actually extends String (in the language sense), but functionality-wise, this may solve your problem.
Joined: Jun 16, 2009
Well I gave String as an example. I probably should have just said any final class.
John's answer is what I was looking for. Isnt this what we call composition?
Joined: Feb 23, 2009
You can write your own implementation of a ResultSet by writing a new class that implements ResultSet, implements all it's methods and delegates all calls on that interface to the wrappered instance, or changes behavior.
The difference is that in the above example your implementation still is a ResultSet, hence all methods that take a ResultSet as an argument will also work with your implementation.
This is the traditional example of Composition which follows the 'Favor Composition over Inheritance' principle.
If someone is really making a class which is a string implementation, then you might consider implementing the CharSequence interface.
One example would be a rope implement of strings, for example http://ahmadsoft.org/ropes/doc/index.html The CharSequence is generally converted to a String using the toString() method, so it is largely interoperable. You can add it with strings for example.
Perhaps you'd like to take a look at the StringBuilder class?