I do not understand that why we need transient keyword to prevent serialization of a particular data member. We can also make it static because static data member can not be serialized. Please guide me if I am wrong!
Asked
Active
Viewed 292 times
-2
-
[Here's an explanation of `static`.](http://stackoverflow.com/questions/2649213/in-laymans-terms-what-does-static-mean-in-java) – Sotirios Delimanolis Oct 14 '15 at 21:56
1 Answers
5
static
does not just make a member not serialized; it also means that there is only one copy of that field for the entire class. If you want there to be a copy of that field for each object, but do not want that object to be serialized, you need transient
; static
will do something completely different.
Making variables static
without fully understanding this is a massively common source of bugs for new Java developers.

user207421
- 305,947
- 44
- 307
- 483

Louis Wasserman
- 191,574
- 25
- 345
- 413