• 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: 21205
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 :-)
 
Why is the word "abbreviation" so long? And this ad is so short?
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!