Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion in transient

 
Indika Sampath
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This statement is complile successfully. But in Kathy & Bates book, they have clearly mentioned that transient can be applied only to instance variables.

can anybody explain this ?


[ June 20, 2007: Message edited by: Barry Gaunt ]
 
Riya Pant
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i also want to know the answer
What I understand from Serialization in context of static and transiet is:
If a class has static variables and this class's object goes under serialization,then this static variable do not get re-initialized when deserialized. But if a variable is declared Transient, it will be re-initialized to its default value when the object is deserialized.


But in the scenario, mentioned by indika, how this variable will behave when the object will be deserialized
 
Prafulla N. Patil
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this will not give error
 
Riya Pant
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what will be its behavior..Will it work like transient or like static variable ??
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps going through thread will help you to understand a bit more.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, They are right.

"Transient" is applicable for only instance variables and NOT for static variables.

Because, the static variables belong to class and NOT to objects, thereby serializing it will not really make sense since the concept of Serialization is storing the state of object and NOT the class!

HtH.
[ June 21, 2007: Message edited by: Raghavan Muthu ]
 
Bharat Makwana
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Indika Sampath:
[QB]

Well,If you write above statement in your code,compiler will treat it as static variable.I have run code with "final static" and transient.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic