I was asked this question in an interview. The interviewer wanted to know how to make an object immutable. and then he asked what if I serialise this object - will it break immutability? If yes, how do I prevent it? Can anyone please help me understand 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
An immutable object is one which cannot be changed once created. You can create such an object by using
private
access modifiers, and thefinal
keyword.If an immutable object was serialized, its raw bytes could be modified so that upon deserialization the object is no longer the same.
This can't be prevented completely. Encryption, checksums, and CRC's will help to prevent this though.