will anyone try to best explain mutable and immutable class ?
Please discuss scenarios where immutable class have an edge over mutable class .
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Apr 22, 2014, 5:58 AM
Shortly we can say as:
When you have a reference to an instance of an object, the contents of that instance can be altered for Mutable objects and When you have a reference to an instance of an object, the contents of that instance cannot be altered for Immutable objects.
VulpesPosted Apr 22, 2014, 5:28 AM
In contrast a mutable class is one where one of more of its fields can be changed after instantiation.
Immutable classes are particularly useful in multi-threaded or concurrent programming which involves 'shared state'. If this shared state is immutable, then there are no synchronization issues when multiple threads or processors access it simultaneously because it simply cannnot be changed.