Could it be serialized if it implements Serializable?

I already saw this: How to check in java that a class implements serializable correctly

I have only a general question. If you create an object (like a circle) like this (suppose there is an import there):

class Circle implements Serializable { int radius; Circle(int radius){ this.radius = radius; } public void updateRadius(int radius){ this.radius = radius } public int getRadius(){ return radius; } } 

Is that all it takes to serialize it? Do I need to add additional methods to it for proper serialization? My class is much more complicated, but he did not want to publish it all when this should provide a sufficient example.

0
source share
3 answers

Very simple answer.

Suppose you live in a specific province of good Canada, which requires all your business communications to be in French.

The name of your business is a chance. It provides debt collection, spamming and user tracking services.

Your parent company is la connerie. Your company does not have the ability to provide debt collection, mailing, and user tracking services in French. In any case, your parent company la connerie conducts all transactions for your company in any case, and they have the opportunity to conduct debt collection, spam marketing and user tracking services in French. Thus, your company cannot be raided by provincial governments - do not worry.

In fact, la connerie does not have the means to run debt collection services, spamming and user tracking services in French, as it is actually owned by du fumier holding company. In addition, du fumier has facilities for debt collection, mailing, and user tracking in French and does this for all of its subsidiaries.

Thus, each small business object under an umbrella can calmly declare that they will IMPLEMENT French debt collection, spam marketing and user tracking services, without requiring each of them to conduct such business communication in France, since they depend on du fumier to do it for them.

Once your company decided to acquire another le merdes du chevre company, and their business is debt collection. The company was recently created and is actually an empty shell. but it is safe from the provincial French linguistic authorities, because it may be up to your company to carry out debt collection in French. Therefore, les merdes du chevre may gladly declare that they WILL IMPLEMENT French debt collection services without raising their finger to do anything about it.

Next week, your company will acquire another les crapes des crabes company, whose business sells crab by-products. However, they do not have the means to sell crab by-products in French. And because of this, you will need to create a department for the sale of crab by-products in French. And if this does not succeed, the provincial linguistic authorities will take the EXCLUSION of sending your company to court for the IMPOSSIBILITY of selling crab by-products in French.

But you can avoid harassment / harassment by the linguistic authorities if you claim that les crapes des crabes is a TRANSIENT entity. You purchased it with the intention of transferring it to the British colony and that you never had the intention of actively using this company to sell crab by-products in the province.

0
source

All instance variables must also be serializable. This can cause problems when working with an external library, and your "serializable" class contains a reference to a non-serializable class.

+6
source

Yes, that’s all you need, as long as the transitive closure of all the referenced objects is all serializable.

Please note that this does not mean that the deserialized object will work - it depends on the semantics of the "Circle". The easiest way to lose is that the new object will be a copy, not an identical object.

+1
source

Source: https://habr.com/ru/post/1445539/


All Articles