On Wed, 14 May 2025 18:16:08 GMT, Roger Riggs <rri...@openjdk.org> wrote:

>> Maybe a good idea at this point if @mkarg could provide an example of server 
>> code benefitting from returning a CharSequence...
>
> The result should be immutable and CharSequence does not provide that. 
> The contents should not be modifiable after the method returns.

A "pure" `CharSequence` *is* immutable, as it does not have mutation methods. 
Also, why *should* the result be immutable? If someone wants to return a 
`StringBuilder` for example (for whatever intent), why shouldn't he allowed to 
do that? In fact, it would be beneficial to return a `StringBuilder` in some 
cases, as it is more efficient to modify (*iff* wanted) than a `String`. It 
should be up to the caller and the provider of the implementation to decide 
about immutability; this is not the API's discretion.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24728#discussion_r2089617093

Reply via email to