Book suggest to implement Serializable interface with custom classes, I just wonder what it achieve? Thanks.
Essentially, implementing Serializable tells Java that it is safe to take your custom class and automatically turn its fields into bytestreams of data.
This of course means that each of your fields must also be safe to automatically turn into bytestreams of data - which means that they must also implement Serializable, or be atomic datatypes. If they don’t, serialization will fail and throw an exception.
That’s a very cursory explanation, of course. I recommend checking out a Java-oriented resource - any basic Java introduction will provide a thorough explanation of Serializable.
Is this a valid method to use in practice? Isn’t serialization slow?