Ad Code

How can we prevent serialization?


How can we prevent serialization?

-) Often there is no need to serialize sockets, streams & DB connections etc because they do no represent the state of object, rather connections to external resources
-) To do so, transient keyword is used to mark a field that should not be serialized
-) So we can mark them as,
o transient Socket s; o transient OutputStream os; o transient Connecction con;
-) Transient fields are returned as nullon reading
Reactions

Post a Comment

0 Comments