RFR: 8372353: API to compute the byte length of a String encoded in a given Charset [v17]

Eirik Bjørsnøs eirbjo at openjdk.org
Wed Feb 25 17:34:10 UTC 2026


On Wed, 25 Feb 2026 17:20:52 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> 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.

Reemerging from my armchair to express a small preference for `encodedLength(Charset)`. 

A `get` prefix does not evoke computation to me, usually the contrary in that it may be a simple getter.

Also, local consistency in String in perhaps more important than global consistency in the JDK for this operation. String does not seem to lean much toward `get` prefixes.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28454#discussion_r2854364358


More information about the core-libs-dev mailing list