Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added 2 CSs

...

Code Block
bgColor#FFcccc
public class OuterSer implements Serializable {
  private int ssn;
  class InnerSer implements Serializable {
    protected String name;
    //...
  }
}

Compliant Solution

This compliant solution recommends against implementing the Serializable interface in the InnerSer class.

Code Block
bgColor#ccccff

public class OuterSer implements Serializable {
  private int ssn;
  class InnerSer {
    protected String name;
    //...
  }
}

Compliant Solution

It is also allowable to declare the inner class as static to prevent its serialization.

Code Block
bgColor#ccccff

public class OuterSer implements Serializable {
  private int ssn;
  static class InnerSer {
    protected String name;
    //...
  }
}

Risk Assessment

Attempting to serialize inner classes can cause instances of the outer class to be serialized and also discourage platform independence.

...