Even if you implement Java in a simple POJO Java class io. Is serializable also a best practice?
•
Java
In general, let a simple POJO Java class implement Java io. Is serializable a best practice?
Solution
Not usually Joshua Bloch said to implement serializable justice He described some shortcomings:
>Reduces the flexibility to change the class implementation in the future - serialization form is part of the class API > more likely to have some errors and security vulnerabilities - attackers can access the class interior in the serialized byte stream > increases the test burden - now you have to test serialization! > Authors who load subclasses – they must also make their subclasses serializable
Of course, sometimes you need a POJO to implement serializable, such as RMI, but if not, your code will be simpler and safer
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码