Should JEP 468 derived withers be opt in?
Adam Gent
me at adamgent.com
Thu Nov 7 14:49:56 UTC 2024
Apologies. I meant instance factory methods and not static methods on my previous message.
On Thu, Nov 7, 2024, at 9:28 AM, Adam Gent wrote:
> One concern I have with "Withers" is that they don't codify the need or
> requirement of multiple fields to be set at the exact time.
>
> Currently folks are probably making static methods on records for
> creation. After (ab)using records in our code base that is less
> academic and more business we frequently have a time field.
>
> record Something(String name, Instant updateTime, ... other fields) {
> static Something withName(String name, Instant updateTime) {
> ...
> }
> // Other with methods always including updateTime.
> }
>
> I admit my example is poor but the idea is that we want to encodify
> that the time needs to be set on each call.
>
> If JEP 468 comes through one could create the record without specifying
> the time field. Basically withers allow each field to be updated
> independently. That is JEP 468 sort of increases the API of existing
> code.
>
> So I wonder if a safer backward compatibility is to provide some sort
> of marker annotation? e.g. `@Withers` placed on the record or some
> other way to mark that the record is safe to have withers.
>
> Thoughts?
>
> Cheers
> -Adam
More information about the amber-dev
mailing list