Transient variables may not be static or final
Amir
Originally posted by zarina mohammad:
Can a variable which is Transient be declared both static and final?
Simon roberts
i tried declaring a variable as follows:
public transient static final int _FRAMEX = 850;
it worked without any error.
is the statement in the simons roberts book correct or incorrect?
help me on this.
thanks
zarina
Originally posted by Amir Ghahrai:
transient keyword means that the variable's value is not stored during serialization, i.e. not persistant. so it will keep changing. by declaring it as final, you counter-effect the transient keyword.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Originally posted by zarina mohammad:
Can a variable which is Transient be declared both static and final?
8.3.1 Field Modifiers
FieldModifiers:
FieldModifier
FieldModifiers FieldModifier
FieldModifier: one of
public protected private
static final transient volatile
The access modifiers public, protected, and private are discussed in �6.6. A compile-time error occurs if the same modifier appears more than once in a field declaration, or if a field declaration has more than one of the access modifiers public, protected, and private.
If two or more (distinct) field modifiers appear in a field declaration, it is customary, though not required, that they appear in the order consistent with that shown above in the production for FieldModifier.
A compile-time error occurs if a final variable is also declared volatile.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |