What does the keyword “transient” mean in Java?
本问题已经有最佳答案,请猛点这里访问。
我看见某处
1 2 3 | <wyn> transient private TrackDAO trackDAO; </wyn> |
谷歌是你的朋友——第一个点击——你也可以先看看序列化是什么。
It marks a member variable not to be
serialized when it is persisted to
streams of bytes. When an object is
transferred through the network, the
object needs to be 'serialized'.
Serialization converts the object
state to serial bytes. Those bytes are
sent over the network and the object
is recreated from those bytes. Member
variables marked by the java transient
keyword are not transferred, they are
lost intentionally.
示例,稍加修改(谢谢@pgras):
1 2 3 4 5 6 7 | public class Foo implements Serializable { private String saveMe; private transient String dontSaveMe; private transient String password; //... } |
Java中的瞬态变量永远不会序列化。
这意味着