Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transient variables

 
Neelima Mohan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cant transient variables be final or static?

Thanks,
Neelima
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The transient keyword is used in serialization. Since only instances can be serialized, and static fields are never serialized, it wouldn't make much sense to allow a combination of transient and static.

Transient variables are not serialized or de-serialized. If they were final they could never again get a value after de-serializing. They will lose the value they had and that value can never again be set, rendering them virtually useless.
 
Neelima Mohan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic