我有以下代码:
String test = "[{\"color\":\"red\"}]";
Class<? extends Base> baseObject = Base.class;
Collection<? extends Base> elements = new ArrayList<Base>();
if (test.startsWith("[")) {
elements.addAll(new ObjectMapper().readValue(test, Collection.class));
} else {
elements.add(new ObjectMapper().readValue(test, baseObject));
}
不过我继续
elements.addAll(new ObjectMapper().readValue(test, Collection.class));
编译警告:
The expression of type Collection needs unchecked conversion to conform to Collection<? extends capture#1-of ? extends Base>
并且对于elements.add(new ObjectMapper().readValue(test, baseObject));
编译错误:
The method add(capture#2-of ? extends Base) in the type Collection<capture#2-of ? extends Base> is not applicable for the arguments (capture#3-of ? extends Base)
怎么了?