Java: Static transient fields Java: Static transient fields java java

Java: Static transient fields


Nope - you said it yourself, static fields aren't serialized.

Kinda weird that the compiler lets you do that though.


In most cases, it is not useful. Static fields are indeed not serialized by the default serializer.

However, static transient fields can be detected via reflection. If someone writes its own serializer and he wants to also serialize static fields, then he might take the transient keyword in consideration and skip the serialization of that particular field.

PS: This answer is posted for the sake of completeness, and is based on Peter Lawrey's comment. Credits to him.