My question here specifically is about treating a CharBuffer as a CharSequence.

The specific issue here is that when acting as a CharSequence, all the
pre-jdk25 methods are relative indexes. JDK 25 added a new method to
CharSequence, but the implementation in CharBuffer uses absolute
indexes.
This also means that implementation in CharBuffer is not consistent
with the default implementation in CharSequence. It seems it should
just be optimized - not change the actual behavior.

This makes it very difficult to pass a CharBuffer (where the position
is not 0) to an api taking a CharSequence - because if that api makes
a switch to start using getChars (rather than charAt), it will break.

On Wed, Jul 2, 2025 at 10:40 AM Brian Burkhalter
<brian.burkhal...@oracle.com> wrote:
>
> Some methods are absolute and some relative:
>
> https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/nio/Buffer.html#transferring-data-heading
>
> On Jul 2, 2025, at 8:35 AM, Brett Okken <brett.okken...@gmail.com> wrote:
>
> CharBuffer implementation of public default void getChars(int
> srcBegin, int srcEnd, char[] dst, int dstBegin) uses absolute
> positioning for the indexes (i.e. ignores the current position).
>
>

Reply via email to