gpt4 book ai didi

Java - 类型不匹配 : cannot convert from element type Object to String

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:55:45 25 4
gpt4 key购买 nike

我有这个错误:

Type mismatch: cannot convert from element type Object to String

这是错误的代码:

public List<String> customPrefixes(PermissionUser u)
{
List returnlist = new ArrayList();
for (String k : u.getAllPermissions().keySet()) {
List perms = (List)u.getAllPermissions().get(k);
for (String s : perms) {
String[] split = s.split(".");
if ((split.length >= 3) &&
(split[0].equalsIgnoreCase("plugin")) &&
(split[1].equalsIgnoreCase("prefix"))) {
returnlist.add(split[2]);
}
}
}
return returnlist;
}

最佳答案

试试这个:

public List<String> customPrefixes(PermissionUser u)
{
List<String> returnlist = new ArrayList<String>();
for (String k : u.getAllPermissions().keySet()) {
List<String> perms = (List<String>)(u.getAllPermissions()).get(k);
for (String s : perms) {
String[] split = s.split(".");
if ((split.length >= 3) &&
(split[0].equalsIgnoreCase("plugin")) &&
(split[1].equalsIgnoreCase("prefix"))) {
returnlist.add(split[2]);
}
}

}

return returnlist;
}

你错过了 "<String>"在列表声明中

关于Java - 类型不匹配 : cannot convert from element type Object to String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23853404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com