• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Can they mix???

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given:
private static final transient Double balance = null;
Can final and transient mix? Madame Sierra's book states that an instance variable marked transient CANNOT be final or static!
 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like there is nothing wrong with that combination. But perhaps Madame Sierra or Sir Bert could give a much better explanation.
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ September 02, 2003: Message edited by: Pradeep Bhat ]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"transient" is redundant because "static" varaibles are always "transient". But there is nothing wrong with specifying both.
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
K -
I'm trying to find where we said that in the book (can you help with a page number?)... anyway here's what I did find that's close:
'The transient modifier applies only to instance variables'.
Your compiler might let you mark a static variable as transient, but static variables aren't part of an object's persistent state, so it's really meaningless. (It's not on the exam and the spec doesn't say.)
'Instance variables can -
Be marked as final or transient'
I guess we should have said 'final and/or transient'
Does that help?
-Bert
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What can't be combined is volatile and final modifiers if it feels close to transient and final. Using both altogether will cause a compiler error. This combination is not in the K&B book, so I'm not sure if the exam's objectives require you to memorize that.
 
I am a man of mystery. Mostly because of this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic