简体   繁体   中英

Serializing mutable objects in java

I am programming a networked turn based java game, and use the java serialization api to serialize the game state each time a player does a move.

To my annoyance, I discovered that the api assumes the objects are immutable. This means that each time I try to send the updated game state, the old game state is received at the clients.

Is there some way to make the objectoutput/objectinputstream forget that an object has already been sent and make a new object each time?

ObjectOutputStream.reset() is what you are looking for: Oracle docs . It forces the stream to send updated objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM