should CharSequence have getChars default method?

Per Bothner per at
Wed Aug 21 14:07:32 PDT 2013

It is tempting to move many of String's methods to
CharSequence.  A dumb default implementation: of CharSequence#t
based on String#T:

    public default T M(args) { return this.toString().M(args); }

If the return type is String, perhaps the return type (in CharSequence)
should be CharSequence:

    public default CharSequence M(args) { return this.toString().M(args); }

Of course this loses because of the toString.  However, in many cases
the implementation from String could be plugged in easily.

Specifically getChars is defined for both String, StringBuilder,
and StringBuffer.  It seems such a method should be moved up in the

I realize time is limited, and this isn't very high priority.
Once you look into the details of each method, and how they're
implemented in String, there will be lots of little decisions.
Still, at least something to consider for Java 9.
	--Per Bothner
per at

More information about the lambda-dev mailing list