开发者

Syntax transition between Vector to TreeMap (java)

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

Thanks


Your 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜