创建一个JavaBean,该JavaBean可用于表示您要创建的对象。
import java.util.List; // 来自 时 代 Java 公 众 号 - nowjava.com class Player { private String firstName; private String lastName; private String position; private int status = -1; public Player() { } public Player(String position, int status) { this.position = position; this.status = status; } public String playerString() { return getFirstName() + " " + getLastName() + " - " + getPosition(); } /*N o w J a v a . c o m - 时 代 Java*/ /** * @return the firstName */ public String getFirstName() { return firstName; } /** * @param firstName * the firstName to set */ public void setFirstName(String firstName) { if (firstName.length() > 30) { this.firstName = firstName.substring(0, 29); } else { this.firstName = firstName; } } /** * @return the lastName */ public String getLastName() { return lastName; } /** * @param lastName * the lastName to set */ public void setLastName(String lastName) { this.lastName = lastName; } /** * @return the position */ public String getPosition() { return position; } /** * @param position * the position to set */ public void setPosition(String position) { this.position = position; } /** * @return the status */ public int getStatus() { return status; } /** * @param status * the status to set */ public void setStatus(int status) { this.status = status; } } class Team { private List<Player> players; private String name; private String city; /** * @return the players */ public List<Player> getPlayers() { return players; } /** * @param players * the players to set */ public void setPlayers(List<Player> players) { this.players = players; } /** * @return the name */ public String getName() { return name; } /** * @param name * the name to set */ public void setNam