Java Reference
In-Depth Information
will be called makes them at best the place to put some last-chance-checking code in objects
that hold references to some kind of resource. Even then, the most a finalizer should do is
make sure that the resource has been freed up by other code, and clean up if it has not.
Given all of this, we change our PlayerImpl class to look like:
package org.oreilly.javaGoodParts.examples.impl;
import java.util.UUID;
import org.orielly.javaGoodParts.examples.statistics.Player;
import org.orielly.javaGoodParts.examples.statistics.Team;
public class PlayerImpl implements Player, Serializable {
private static final long serialVersionUID = 1;
private UUID id;
private String name;
private String filePrefix;
private Team team;
private Position pos = Position.Utility;
private boolean changed = false;
public PlayerImpl(String playerName) {
name = playerName;
id = UUID.randomUUID();
public PlayerImpl(UUID playerId, String prefix) {
id = playerId;
filePrefix = prefix;
try {
ObjectInputStream readIn = new ObjectInputStream(
new FileInputStream(prefix + id.toString()));
PlayerImpl copy = (PlayerImpl) readIn.readObject();
id = playerId;
Search WWH ::

Custom Search