The inner class contains a reference to its outer class, so an attempt to serialize the inner will also serialize the outer - as well as any other objects that may have external ones. This can lead to a huge graph of objects. Or it may fail if the external state cannot be serialized (for example, an InputStream object).
However, there are times when you need to make Serializable inner classes, even if you never plan to serialize them. For example, if you work with Swing.
If you plan to serialize these objects, I would question why they should be inner classes regardless of performance. Typically, you are going to serialize data containers, and such containers rarely (if ever) need a reference to some kind of "parent" class. Consider making these objects nested (static) classes, not inner classes.
kdgregory
source share