4 ms·
What about Records and immutable Collections, Sets, Maps? Isn't it possible to achieve what you want with that?
by barbarbar 4y ago
What about Records and immutable Collections, Sets, Maps? Isn't it possible to achieve what you want with that?
- kaashif 4y agoNot really. In Java you can do all kinds of things with immutable wrappers, but the language doesn't help you and it doesn't come for free for your own types. In C++ you can write a class with some methods that mutate, and some const methods that can't mutate anything, and you can pass around const references through which mutation is guaranteed to be impossible. This all comes for free.
- barbarbar 4y agoThis was added a couple of years ago https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Record.html https://docs.oracle.com/en/java/javase/17/docs/api/java.base.... I was thinking that would make it possible to create unmodifiable data objects using that (and not Object as base class).