Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
asgs115633yJava wasn't designed with immutability in mind. So, all objects are mutable by default, unless you work around by making them not mutable
So, there is nothing to reason about their adv/disadvantages -
Performance mostly. You really don't want to be allocating new objects and copy the old data over on each little change
-
Root825083yImmutability is great for detecting bugs, but at a very heavy performance cost. It’s an expensive safety net.
-
I think it’s easy to overestimate the performance discredits of immutability. Optimising compilers can reduce the load incurred from having to recreate large objects on minor changes by reallocating unchanged memory. Also you often will use more granular object composition when working with immutable structures because you can’t configure a monolith for every use case.
-
I'll take the high road and reflect the question back at ya:
Why should everything (!) be immutable?
Just think about it, go crazy for a bit and try to invent some scenarios.
Immutability is one of many nice concepts in programming, but it doesn't fit everything.
Related Rants
why are there some mutable objects in java? Why can everything just be immutable? Are there any disadvantages?
question
java