• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can they mix???

 
K Ville
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • 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!
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • 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.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ September 02, 2003: Message edited by: Pradeep Bhat ]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"transient" is redundant because "static" varaibles are always "transient". But there is nothing wrong with specifying both.
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • 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
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic