Ok my fault, my meaning was : A inner class can not be serialized (ad deserialized) because a no static inner calss can not have static members (and for serilize a class needs a public static final long verionUI).The code below argue this.
When I run your code, I get a java.io.NotSerializableException: SerilizeInnerClass. And it's true. That class is not serializable. I implement Serializable in the class declaration, remove the problematic stream close() invocations and it works fine:
Ok you are right.But why ? If the main class(in out case the outer class) is serializable all its inner class inherit this ? It is logic - a inner class can be a part from the outer class state, and the state is serialized. Is this right or there are others reasons ?
Only Primitive types in java gets serialised automatically. If you wnat to serialize any object its type must implement serializabale interface and hence as in the previous case when the inner class imaplemented the seraializable interface it was possible for serialising. The non-static inner class is a member of a class and does not inherit the properites of the Enclosing class.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop