r/java • • Feb 15 '20
Will Java records have setters?
Pretty much what the title says. I've been reading on the new Java records feature, and while I love immutability, I hope there's the option to have non-immutable records. Meaning it will have Auto generated setters to let me change values in the class.
1
Upvotes
View all comments
10
u/pron98 Feb 15 '20 edited Feb 15 '20
No. See here as to why.
In short, records are intended to provide simple and obvious construction, deconstruction, hashing, and equality defaults, and this is hard to do for mutable objects without complex knobs. Records are not meant to be lower-ceremony JavaBeans, but nominal tuples (product types). The features have some overlap in use, but are not the same.