<分区>
我想确定我得到的对象是否是一个字符串列表。 这是我的代码:
Object obj = plugin.getConfig().get("groups");
if(obj instanceof List<?>){ // Is the Object a List ?
List<?> list = (List<?>) obj;
if(list.get(0) instanceof String){ // Does the List contain Strings ?
List<String> groupList = (List<String>) list;
}
}
但是 Eclipse 说第 5 行的最后一个转换不安全:
Type safety: Unchecked cast from List<capture#3-of ?> to List<String>
我该如何解决?我也试过
List<String> groupList = (List<String>) obj;
...但我仍然遇到同样的错误(基本上)。