Campbell Ritchie wrote:I thought Matcher and Pattern were both final.
Might it be worth requesting an update for Matcher to accept a StringBuilder?
They are final, so for Matcher it wouldn't be too hard to add the method. I just never bothered to request it. I also doubt they would add it, as there is quite some code involved for the methods that use StringBuffer. For reference, appendReplacement is 98 lines (excluding method signature and closing }). The others aren't a problem, but I doubt Oracle would want to copy those 98 lines of logic.
Winston Gutkowski wrote:
Rob Spoor wrote:I'd love to see updates to those classes to accept StringBuilder...
Actually, I'd love to see an interface that encapsulates both; since their APIs are identical. Then all you'd need to do it to retrofit it into places where it makes sense.
I've actually written one myself, and it works great; but it was darn verbose because I don't have access to the original classes - and those suckers have LOTS of methods (far too many in my opinion).
There actually is a common super class - java.lang.AbstractStringBuilder. However, it's not public, and I honestly don't see a reason why. Making it public wouldn't break anything (reflection still finds the class), the only reason would be to the class hierarchy of StringBuffer consistent between 1.4 and 5.0. Which is a rubbish reason if reflection can find it anyway.
Quick question: How many people here still use String when CharSequence would probably be better? 
I've actually rewritten some parts of my code recently to accept CharSequence where it first accepted String. The class is still called Strings though
