我有一个叫做cardNames的类。在每个新游戏中,我都会创建一个新的cardNames实例,该实例对应于当前使用的卡牌。我希望将它们设置为静态,这样就不必发送cardNames对象的副本。
这合法吗?
public class cardNames
{
private static String[] characters;
private static String[] weapons;
private static String[] rooms;
private int totalCards;
public cardNames(String[] theCharacters, String[] theWeapons, String[] theRooms)
{
characters = Arrays.copyOf(theCharacters, theCharacters.length);
weapons = Arrays.copyOf(theWeapons, theWeapons.length);
rooms = Arrays.copyOf(theRooms, theRooms.length);
totalCards = characters.length + weapons.length + rooms.length;
}
public static String[] getCharacters()
{
return Arrays.copyOf(characters, characters.length);
}
创建新的cardName对象后,我会有一套新的角色,武器和房间吗?