Java Reference
In-Depth Information
void removePlayer(Player toRemove);
We now change the implementation class we have for this interface to use a parameterized
version of the HashSet class that matches the version used in the interface:
package org.oreilly.javaGoodParts.examples.impl;
import java.util.HashSet;
import java.util.Set;
import org.oreilly.javaGoodParts.examples.statistics.Player;
import org.oreilly.javaGoodParts.examples.statistics.Team;
* A third implementation of the Team interface, using
* a HashSet as the backing store for the Players on
* the team, after the interface has been changed to
* return a Set from the getPlayers() method.
public class TeamImpl implements Team {
private String name;
private HashSet<Player> players = new HashSet<Player>();
* Create a TeamImpl object, with the name
* supplied.
public TeamImpl(String teamName) {
name = teamName;
* Return a <code>String</code> that is the name of
* this team.
public String getName() {
return name;
* Return a list of the players that are on this
* team.
Search WWH ::

Custom Search