Would like to know how to translate all my logic from use of :
static List<ServerThread> s_PlayersOnServer = new Vector<ServerThread>();
To
static Map s_PlayersOnServer = Collections.synchronizedMap(new TreeMap());
For example I have this sample:
ServerMain.s_PlayersOnServer.get(clientSerialNumber-1).setPlayerName(playerName);
And 开发者_如何学编程after I switched to Map implementation but the same logic doesn't work:
ServerMain.s_PlayersOnServer.get(clientSerialNumber).setPlayerName(playerName);
The function setPlayerName is not known in the new context and I don't know why
ThanksYour List is typed correctly whereas your Map isn't.
Consider
static Map<Integer, ServerThread> s_PlayersOnServer = Collections.synchronizedMap(new TreeMap<Integer, ServerThread>());
If the clientSerialNumber is indeed an integer.
Regards
精彩评论