문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

No, your class must implement Serializable interface. Java does not make such bottom-to-top assumptions about the data.

class Tuple implements Serializable {

    private static final long serialVersionUID = 5316748056989930874L;

    //whatever
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top