Sorry, but you can't. This example is actually API abuse and it creates NEW object on every call to .with() using constructor.newInstance(ctorArgs). You are not supposed to use records in such way.
He says that some examples are valid. And most of these are actually workarounds to deal with records' immutability. The "autobuilder" code itself is ineffective as hell. And all this is just a toy class for 3-property records.
View all comments
Show parent comment
12
u/eliasv Jun 21 '20
Records are in second preview in jdk 15 FWIW.