Java: When to add readObjectNoData() during serialization?

后端 未结 4 1675
广开言路
广开言路 2021-02-02 10:58

I am reading the serialization chapter in Effective Java. I am trying to understand the paragraph below, which is found in the book.

If you implemen

4条回答
  •  一个人的身影
    2021-02-02 11:15

    An invariant in your Person class could be something like:

    age must be greater than 0
    

    So, when the Person class is instantiated with the default value, 0 (see here: http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html) you will have violated that invariant.

    However, given the default constructor you will be fine :)

提交回复
热议问题