RFR: 8372353: API to compute the byte length of a String encoded in a given Charset [v17]
Liam Miller-Cushon
cushon at openjdk.org
Wed Feb 25 17:04:44 UTC 2026
On Wed, 25 Feb 2026 16:39:45 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> Liam Miller-Cushon has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Rename getBytesLength to getByteLength
>
> src/java.base/share/classes/java/lang/String.java line 2119:
>
>> 2117: * @since 27
>> 2118: */
>> 2119: public int getByteLength(Charset cs) {
>
> `getEncodedLength(Charset cs)` is a stronger name, more evocative of the value being computed.
> The name should not rely on the argument to hint at its primary function.
Thanks @RogerRiggs and @liach, I've started updating the CSR and will make the changes in the PR to rename it from `getByteLength`.
I wasn't sure what the overall approach is for JDK APIs of when to include a `get` prefix. I think that either `getEncodedLength(Charset cs)` or `encodedLength(Charset cs)` are good options, happy to go with whichever the Core Libraries team thinks is best :)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28454#discussion_r2854242033
More information about the core-libs-dev
mailing list