<i18n dev> RFR: 8368172: Make java.time.format.DateTimePrintContext immutable [v6]

Roger Riggs rriggs at openjdk.org
Thu Oct 2 14:24:23 UTC 2025


On Thu, 2 Oct 2025 03:08:32 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:
> 
>   Improve javadoc for optional parameter in DateTimePrinterParser#format method

The DateTimePrintContext is exactly that, providing the context for the formatting. It holds the references to the Temporal that has the value and the appendable that is the destination. And in the committed implementation holds the current optional count/flag.  If its is to be immutable, then you need to create a second one and pass it down to/through format().
It will be a small, short lived object.

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

PR Comment: https://git.openjdk.org/jdk/pull/26913#issuecomment-3361450548


More information about the i18n-dev mailing list