<i18n dev> RFR: 8372353: API to compute the byte length of a String encoded in a given Charset [v17]
Roger Riggs
rriggs at openjdk.org
Wed Feb 25 17:24:19 UTC 2026
On Wed, 25 Feb 2026 17:00:39 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:
>> 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 :)
I agree that `encodedLength(cs)` is a cleaner name and consistent with more of the String API.
The `get` was a carry over from the original method.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28454#discussion_r2854340559
More information about the i18n-dev
mailing list