A common scenario in web applications:
- application has lots of classes that need to be stored in Session and are Serializable
- developer gets a bunch of warnings about "Serializable class does not implement serialVersionUID"
- developer shrugs and clicks on IDE's "add serialversionUID" and problem is solved?
I don't like automatically adding serialVersionUID in principle since the solution essentially means that
- most importantly developer states "I know when my changes break serialization and when they do not, and want to control that instead of JVM", when in fact he does not know those things and does not want to control them
- adding serialVersionUID = 6266256561409620894L is confusing and ugly (ok, you can use 1L)
I understand adding serialVersionUID in an application where class compatibility is an issue and developers actively take that into consideration and understand related issues.
In a typical web application it's not very important when the serialization of classes breaks or not. When a new version is deployed, some extraneous serialized sessions may be broken but this is usually not a problem (and few applications actually properly handle version-compatibility of serialized sessios).
Bottom line: isn't advice "Always define the serialVersionUID explicitly in your source files" simplistic?