final transient fields and serialization

后端 未结 5 1828
无人及你
无人及你 2020-12-13 03:46

Is it possible to have final transient fields that are set to any non-default value after serialization in Java? My usecase is a cache variable — that\'s why i

5条回答
  •  感动是毒
    2020-12-13 04:13

    The general solution to problems like this is to use a "serial proxy" (see Effective Java 2nd Ed). If you need to retrofit this to an existing serialisable class without breaking serial compatibility, then you will need to do some hacking.

提交回复
热议问题