duchien85 / kryo

Automatically exported from code.google.com/p/kryo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

not all fields are correctly serialized #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
fields with the modifier final should be serialized, as they can contain
runtime data. Same goes to static fields

class Foo {
    static int count = 0;
    final int ID;

    public Foo() {
        ID = count++;
    }
}

the only fields not needed to be serialized are: "transient", "static final"

Original issue reported on code.google.com by kp86...@googlemail.com on 30 Nov 2009 at 3:36

GoogleCodeExporter commented 9 years ago
A final field cannot be serialized because the value cannot be written. This 
cannot
be circumvented through setAccessible(true) because the JIT can optimize final 
fields
and changing the actual field might not always update the value used in 
calculations
inside method bodies.

Static fields should not be serialized because they are separate from the 
individual
objects that are being serialized. Deserializing a single object should not 
change
the values of static fields directly.

Original comment by nathan.s...@gmail.com on 6 Jan 2010 at 6:38

GoogleCodeExporter commented 9 years ago

Original comment by nathan.s...@gmail.com on 7 Apr 2010 at 2:47