[英]Final static field serialization
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.带有
final
关键字的值被序列化, static
值不被序列化,在static transient
中, transient
被忽略等等。 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:我几乎阅读了所有内容,但我有一个问题,我找不到答案,无论是在谷歌还是在 Stack Overflow 上:
What happens when data is static final
?当数据是
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
?它会被视为
final
还是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
final修饰符只声明一旦变量被赋值,就不能再改变
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.