Vector 到 TreeMap 之间的语法转换 (java)
想知道如何将我的所有逻辑从使用:
static List<ServerThread> s_PlayersOnServer = new Vector<ServerThread>();
例如
static Map s_PlayersOnServer = Collections.synchronizedMap(new TreeMap());
我有这个示例:
ServerMain.s_PlayersOnServer.get(clientSerialNumber-1).setPlayerName(playerName);
在我切换到 Map 实现之后,但相同的逻辑不起作用:
ServerMain.s_PlayersOnServer.get(clientSerialNumber).setPlayerName(playerName);
函数 setPlayerName 在新上下文中未知,我不知道为什么
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的列表输入正确,而您的地图则不正确。
考虑
clientSerialNumber 是否确实是整数。
问候
Your List is typed correctly whereas your Map isn't.
Consider
If the clientSerialNumber is indeed an integer.
Regards