com.pnfsoftware.jeb.util.serialization.annotations.SerStaticOk |
This annotation is used to prevent the generation of warnings when static fields (they are not serializable) are of a type that is serializable.
Why is this a potential problem? Consider the following code:
@Ser class A { @SerId(1) int x; A(int x) { this.x = x; } } @Ser class B { // static, not ser. static A a = new A(3); @SerId(1) A b; void copyref() { this.b = a; } } B o = new B(); o.copyref(); // ... // serialization happens
=> when is "o.b == B.a" true?
- when working on a new instance, it is true
- when working on a deserialized instance, it is false, since B.a is NOT restored; it is
reinstantiated the first time an object of type B is used by the deserialization process
=> reference equality would work only on a non-deserialized objects graph
=> therefore, proper equals/hashCode would be required, if for instance, deep-equality is be used
between such statics and non-static field
A safe solution is to consider using a static factory to create objects of type A.
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
java.lang.annotation.Annotation
|