RFR: 8354724: Methods in java.io.Reader to read all characters and all lines [v19]

Markus KARG duke at openjdk.org
Wed May 14 19:40:56 UTC 2025


On Wed, 14 May 2025 18:16:08 GMT, Roger Riggs <rriggs at 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


More information about the core-libs-dev mailing list