From K&B: "If you serialize a collection or an array, every element must be serializable! A single non-serializable element will cause serialization to fail. Note also that while the collection interface are not serializable, the concrete collection classes in the Java API are."
What confuses me a little is the last sentence. Should it be interpreted as if I inherit, and/or implement, a class/interface that is not serializable, it is still OK to have elements of that class in e.g. an array and serialize that array, knowing off course that any inherited members will not be part of the serialization process? The rules for non-serializable superclasses thus applies also to interfaces that I implement, though interfaces have no member variables and falls out of the serialization process by design. I think I know the answer but I just want to double-check to make absolutely sure.
" ... Note also that while the collection interface are not serializable, the concrete collection classes in the Java API are."
What confuses me a little is the last sentence.
Say, you have a serializable class containing this member:
Then you can serialize objects of that class. That's because the object type of list is ArrayList, which is serializable. It is not important here that the reference type is List, which is not serializable.
However when you have a class like
... it is not possible to use a Banana object as a member in a serializable class. Unless you mark it transient.
I think, that's all K&B wanted to express with this sentence.
Considering arrays: I find arrays a bit confusing when it comes to serialization. e.g.
prints out: oneObject is Serializable? false objectArray is Serializable? true
So, an array always IS-A Serializable. But when you have an array of non-serializable objects as a member in your class (implementing Serializable), you cannot serialize it. Famous NotSerializableException.
An array generally is serializable and it's up to you to see that all elements in the array are objects of classes that implement Serializable.