Java Serialisation is a way to persist object structures.
It is best practice for serialisable class to declare serialVersionUID
as a private static final long
compile-time constant. This is used to check that object data and class code are claimed to be compatible.
So why is Eclipse telling you about this? Probably, the class that you are extending (or potentially interface you are implementing) implements java.io.Serializable
. That means that all subtypes, including yours are serializable. Almost certainly you don't care. You should be able to clear the warnings by applying @SuppressWarnings("serial")
on the class or package (in package-info.java
). If you want to forcibly prevent instances of your class being serialised, then add (from memory):
private static final java.io.ObjectStreamField[] serialPersistentFields = {
null
};
private void writeObject(
java.io.ObjectOutputStream ou
) throws java.io.IOException {
throw new java.io.NotSerializableException();
}
private void readObject(
java.io.ObjectInputStream in
) throws java.io.IOException, java.lang.ClassNotFoundException {
throw new java.io.NotSerializableException();
}
private void readObjectNoData(
) throws java.io.ObjectStreamException {
throw new java.io.NotSerializableException();
}
It's probably not the best thought out system in the world (although it is much better than many people give it credit for).