On Mon, May 20, 2013 at 5:30 PM, David Holmes <david.hol...@oracle.com>wrote:
> On 21/05/2013 3:55 AM, Martin Buchholz wrote: > >> This is __the__ fundamental question of whether to add >> CharSequence.getChars at all. >> >> If none of the objects in the jdk can trust any of the others, they will >> spend all of their time making defensive copies and unmodifiable wrappers. >> > > But you are not limiting this to objects in the jdk! The CharSequence > could come from anywhere. If the CharSequence is actually a > String/StringBuffer/**StringBuilder then use the optimization. But > otherwise you are just violating encapsulation. > David, Yes, I understand. It's far less obviously bad than having an API that returns an internal array. Here there would have to be a malicious CharSequence, and the owner of the StringB**er has to be willing to call the append method on it. Like I said, This is __the__ fundamental question of whether to add CharSequence.getChars at all. I can appreciate the argument that getChars is simply too insecure to be found in a public interface. But it would be sad if we couldn't enable optimizations like this.