次のコードがあります。
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)
なにが問題ですか?