Actually it looks like the CharBuffer java doc explicitly states that
all CharSequence should be relative:

> This class implements the CharSequence interface so that character buffers 
> may be used wherever character sequences are accepted, for example in the 
> regular-expression package java.util.regex. The methods defined by 
> CharSequence operate relative to the current position of the buffer when they 
> are invoked.

https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/nio/CharBuffer.html

On Wed, Jul 2, 2025 at 10:58 AM Brett Okken <brett.okken...@gmail.com> wrote:
>
> 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