开发者

Syntax transition between Vector to TreeMap (java)

开发者 https://www.devze.com 2023-03-19 04:08 出处:网络
Would like to know how to translate all my logic from use of : static List<ServerThread> s_PlayersOnServer = new Vector<ServerThread>();

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

精彩评论

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

关注公众号