1.

Why Does The Eclipse Compiler Create A Different Serialversionuid From Javac?

Answer»

Serializable classes compiled with Eclipse are not compatible with the same classes compiled using javac. When classes compiled in Eclipse are written to an object stream, you may not be able to read them back in a program that was compiled elsewhere. Many people blame this on the Eclipse compiler, assuming that it is somehow not conforming properly to spec. In fact, this can be a problem between any two compilers or even two versions of a compiler PROVIDED by the same vendor.

If you need object serialization, the only way to be SAFE is to explicitly define the serialVersionUID in your code:

class MyClass implements Serializable {

public static final long serialVersionUID = 1;

}

whenever your class changes SAY it is incompatible with previously serialized versions, simply increment this number.

Serializable classes compiled with Eclipse are not compatible with the same classes compiled using javac. When classes compiled in Eclipse are written to an object stream, you may not be able to read them back in a program that was compiled elsewhere. Many people blame this on the Eclipse compiler, assuming that it is somehow not conforming properly to spec. In fact, this can be a problem between any two compilers or even two versions of a compiler provided by the same vendor.

If you need object serialization, the only way to be safe is to explicitly define the serialVersionUID in your code:

class MyClass implements Serializable {

public static final long serialVersionUID = 1;

}

whenever your class changes say it is incompatible with previously serialized versions, simply increment this number.



Discussion

No Comment Found