top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Java: Why we need transient keyword to prevent serialization of a particular data member?

+1 vote
75 views

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.

posted Oct 15, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

static does not just make a member not serialized; it also means that there is only one version of that field for the entire class.

If you want there to be a version 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.

answer Oct 15, 2015 by Salil Agrawal
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...