• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

transient + static

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Jane:
Can transient be used together with static to modify a variable?
Is the following statement correct?
final transient static private double PI=3.1415927;
From KM's book that "the transient modifier should not be specified for static variables, as these do not belong to objects." p.126
Thanks.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jordan,
The java compiler won't stop you from doing it, but logically it doesn't make sense. Transient variables only relate to an objects' state. Class variables (static) don't relate to state because only one exists for all objects of that class type. Therefore, you are telling the serialization method not to serial a variable that it won't serialize anyway!
Regards,
Manfred.
 
reply
    Bookmark Topic Watch Topic
  • New Topic