<i18n dev> RFR: 8368172: Make java.time.format.DateTimePrintContext immutable [v4]
Roger Riggs
rriggs at openjdk.org
Wed Oct 1 20:19:34 UTC 2025
On Fri, 26 Sep 2025 04:04:40 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> I propose to make j.t.f.DateTimePrintContext immutable.
>>
>> Currently, DateTimePrintContext has only one mutable field, optional. This can be replaced by adding an optional parameter to the DateTimeFormatter.formatTo method.
>>
>> Immutable DateTimePrintContext can be optimized by escape analysis, such as immutable object optimization.
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
>
> add DateTimePrinterParser#withOptional, from @RogerRiggs
The necessity to replace the nested PrinterParsers in CompositPrinterParser.withOptional is an ugly feature of the design.
At some point, someone will complain about that waste of memory and overhead.
Only the composite printer has the static optional attribute.
The rest are due to the nesting and it is a reasonable design choice to pass explicitly to each formatter as in cac20038d26a6e836cf427deee8a0942a23acc4d.
It would be good to keep the design optional in parsing to be aligned with the PrinterParser design to avoid the designs drifting apart.
And the documentation should more completely describe how the static and nested optionality cases are complementary.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/26913#issuecomment-3357981670
More information about the i18n-dev
mailing list