transient

Java static serialization rules?

懵懂的女人 提交于 2019-11-26 09:36:34
问题 I\'m working on a save state serialization with a few static methods and fields. I could have sworn though that serialization and static\'s caused mayhem. Should I make all static\'s transient? And will inflating the calls restore the statics as normal? 回答1: static s are implicitly transient , so you don't need to declare them as such. Serialization is for serializing instances , not classes . static fields (methods are irrelevant since they are part of the class definition so they aren't

Why does Java have transient fields?

狂风中的少年 提交于 2019-11-26 03:14:18
问题 Why does Java have transient fields? 回答1: The transient keyword in Java is used to indicate that a field should not be part of the serialization (which means saved, like to a file) process. From the Java Language Specification, Java SE 7 Edition, Section 8.3.1.3. transient Fields: Variables may be marked transient to indicate that they are not part of the persistent state of an object. For example, you may have fields that are derived from other fields, and should only be done so

Why does JPA have a @Transient annotation?

馋奶兔 提交于 2019-11-26 01:56:05
问题 Java has the transient keyword. Why does JPA have @Transient instead of simply using the already existing java keyword? 回答1: Java's transient keyword is used to denote that a field is not to be serialized, whereas JPA's @Transient annotation is used to indicate that a field is not to be persisted in the database, i.e. their semantics are different. 回答2: Because they have different meanings. The @Transient annotation tells the JPA provider to not persist any (non- transient ) attribute. The