Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Transient variables  RSS feed

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

Thanks,
Neelima
 
Sheriff
Posts: 21305
87
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 :-)
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!