Mutable vs immutable objects

Well, there are a few aspects to this. Mutable objects without reference-identity can cause bugs at odd times. For example, consider a Person bean with a value-based equals method: Map<Person, String> map = … Person p = new Person(); map.put(p, “Hey, there!”); p.setName(“Daniel”); map.get(p); // => null The Person instance gets “lost” in the map … Read more

What is meant by immutable?

Immutable means that once the constructor for an object has completed execution that instance can’t be altered. This is useful as it means you can pass references to the object around, without worrying that someone else is going to change its contents. Especially when dealing with concurrency, there are no locking issues with objects that … Read more

What is the difference between shallow copy, deepcopy and normal assignment operation?

Normal assignment operations will simply point the new variable towards the existing object. The docs explain the difference between shallow and deep copies: The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances): A shallow copy constructs a new compound object and … Read more