Java contains a lot of classes (like in Swing) which implement the dreaded and error prone interface Serializable.
If you implement, say, a new TableModel by extending AbstractTableModel, the new model must be serializable but what if it contains internal data types which aren’t serializable and which don’t have to be since you don’t plan to use this feature anyway?
In such a case, tools like Sonar go crazy. The either complain that “Class Foo defines non-transient non-serializable instance field bar“.
So I make that field transient just to get “The field Foo.bar is transient but isn’t set by deserialization”
Is it possible to say “No, this class isn’t serializable, and I don’t want it to be” in such a way that you don’t get any errors in tools like Sonar?
Quoting from this JavaRevisited article (see #8):
So you just need to paste this into your class: