Perhaps slightly better is this variant, which adds doc for the @serialField's.
/** * @serialField rnd long * seed for random computations * @serialField initialized boolean * always true */ private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField("rnd", long.class), new ObjectStreamField("initialized", boolean.class), }; /** * Saves the {@code ThreadLocalRandom} to a stream (that is, serializes it). */ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { java.io.ObjectOutputStream.PutField fields = out.putFields(); fields.put("rnd", UNSAFE.getLong(Thread.currentThread(), SEED)); fields.put("initialized", true); out.writeFields(); } On Mon, Feb 25, 2013 at 2:13 PM, Martin Buchholz <marti...@google.com>wrote: > Me too! > >