Recently, I've been reading about serialization and everything looks pretty understandable. Values with final
keyword are serialized, static
values are not serialized, in static transient
, transient
is ignored so on and so on. I have read almost everything, but I have one question, for which I could not find the answer, not in google nor on Stack Overflow:
What happens when data is static final
? Which one of them overcomes the other? For example:
interface Foo{
int value = 10; // by default it is public static final
}
How will the value from that interface be serialized, if i implement it in any of my classes? Will it be treated as final
or static
?
A static final variable will not be serialized, since just like a static variable,is a class variable independent of instances. The final modifier states only that once the variable is assigned, it can no longer be changed
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.