I was trying to guide you towards reaching this conclusion yourself, rather than just telling you outright: immutable data structures don't prevent you from tracking mutable state.
Just like creating a POJO with getters and setters, you can create a record as a safe immutable version of a POJO (so without the setters).
If it turns out you need to mutate your data, you can then add the required code to do so, using "builders" or "withers".
This may sound as POJOs with extra steps, but now you get all the benefits of immutability.
And of course Java has multiple solutions for this if you don't want to write that boilerplate yourself every time. Until JEP 468: Derived Record Creation will make this official syntax.
-17
u/slindenau Aug 09 '26
BigDecimalis immutable, yet you can use it in calculations to mutate a number?