aspose file tools*
The moose likes Mock Exam Errata and the fly likes transient + static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "transient + static" Watch "transient + static" New topic
Author

transient + static

jordan gong
Ranch Hand

Joined: Jun 12, 2001
Posts: 37
Hi, Jane:
Can transient be used together with static to modify a variable?
Is the following statement correct?
final transient static private double PI=3.1415927;
From KM's book that "the transient modifier should not be specified for static variables, as these do not belong to objects." p.126
Thanks.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Jordan,
The java compiler won't stop you from doing it, but logically it doesn't make sense. Transient variables only relate to an objects' state. Class variables (static) don't relate to state because only one exists for all objects of that class type. Therefore, you are telling the serialization method not to serial a variable that it won't serialize anyway!
Regards,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: transient + static
 
Similar Threads
transient variables
how to exclude a class member from hibernate mapping?
making a mostly anonymous Comparator be Serializable
static / transient
is trasient + static valid ??