How can one make a Java class immutable, what is the need of immutability and is there any advantage to using this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Immutability can be achieved mainly in two ways:
final
instance attributes to avoid reassignmentAdvantages of immutability are the assumptions that you can make on these object:
Immutable class are those whose objects cannot be changed after creation.
Immutable classes is useful for
Example
String Class
Code Example