【发布时间】:2023-03-25 23:45:02
【问题描述】:
我正在创建一个包含两个板的游戏: http://imgur.com/nrCX5Ux
我想将“A”链接到“.”。两者都是字符串数组。 我想用这个:
indexesOfBoard.put("A", ((morris.START[0].charAt(0))));
然后我收到如下错误:
The method put(String, String) in the type HashMap<String,String> is not applicable for the arguments (String, char)
如果我将 HashMap 更改为 < String, char>,我会得到:
Syntax error on token "char", Dimensions expected after this token
【问题讨论】:
-
使用
Character。您需要使用对象而不是原语 -
顺便说一句,如果您对错误的含义感兴趣,
Map<String, char[]>是合法的,因此编译器希望添加这些数组括号。