Search code examples
javastringserializationcomposite

Are composites of serializable objects also serializable?


If I have a serializable type e.g. String and make a class

class Tuple {

  String s1 = "Hello";
  String s2 = "World";

}

Then will this class also be serializable because both strings are, or will it not be serializable because it doesn't implement the serializable interface?


Solution

  • No, it won't. Class implementing Serializable interface can be serialized. Not a class having has-a relationship with Serializable class objects.

    You may like to read about Serializable here.