• Post Reply Bookmark Topic Watch Topic
  • New Topic

[about transient]....  RSS feed

 
chao-long liao
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some books say transient variables can't be static,
but some say transient variables can be static.
Oh my god.which statement is true???
Thanks for help...
 
Padmaja Balaji
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
RHE book says (pg 90) "Transient variables may not be final or static".
Note the word "may". Can anyone further break down the sentence and explain with simple examples ?
I am also confused!!!
- Padmaja
 
Reda Mokrane
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
it is legal to have static transient variables.
try it out!!
also check the errata for your book? may be the book is wrong.
reda
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
The keyword 'transient' marks a variable as not being part of the persistent state of an object; meaning, if the object is Serialized, that variable need not be saved as part of the object.
The default behaviour for Serialized objects is to ignore 'static' fields. So while it's legal to declare a variable as both 'static' and 'transient' there's not much point to it.
Hope that helps.
PS you can also declare 'final transient' or 'final transient static' variables without a compile-error.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited August 04, 2001).]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!