Immutable objects are also automatically thread-safe and have no synchronisation issues. They can also never exist in unknown or undesirable state because of an exception. Because all initialisation occurs at construction time, which is atomic in Java, any exception occurs before you have an object instance. Joshua Bloch calls this
failure atomicity: success or failure based on mutability is forever resolved once the object is constructed.
one of the best features of immutable classes is how well they fit into the composition abstraction. In the next installment, I'll start investigating composition and why it is so important in the functional-thinking world.
阅读(1012) | 评论(0) | 转发(0) |