|
|
|
|
|
by kaashif
1416 days ago
|
|
> records/pure immutable data classes Example? As far as I know, Java has final, which means that particular reference can't be re-assigned, but the object referred to remains mutable. You have to resort to e.g. having separate immutable and mutable interfaces or whatever to restrict a someone from mutating your object. If you want an immutable data class more than one level deep, I don't know if there's a convenient way to do that like there is with const in C++ (or the default behaviour in Rust). But I'm not a Java programmer, I haven't really kept up with the language. Happy to be proven wrong. |
|
Nonetheless, recently more and more standard classes are made deliberately immutable, and there was a proposal for frozen arrays as well (not sure on their status).