Hi,
i have a Question about the serialVersionUID for abstract classes.
first i will describe a simple example to show my problem.
abstract class A implements Serializable {
private int value;
public A(int value) {
this.value = value;
}
protected abstract void doSomething();
}
class B extends A {
private static final serialVersionUID = 8373629029L;
public B(int value) {
super(value);
}
protected void doSomething() {
//do something
}
}
B is a ValueObjects on a Server and transmitted to a Client Application.
When i change the abstract super class A i get an exception on the client because the serialVersionUID does not mathc to the Client anymore
So i changed the " implements Serializable" Statement down to B. And tried the same. Then i get an InvalidClassException because with following hint "no valid constructor". So i also have to make A Serializable and also need a defined serialVersionUID for A.
I think there is something i don't unterstand in the serialization Mechanism in Java.
Why does it makes sense to adda serialVersionUID to an abstract class? And how do i generate the UID with the "serialver" tool deliversd with the JDK form a class which i cannot instanciate?
Edited by: kbj on Jan 23, 2009 7:14 AM