0

我正在尝试按如下方式创建多图:

Multimap<String, ? extends A> order = LinkedListMultimap.create();
B b = new B();
order.put("key", b); // shows error

B在哪里

class B extends A {} 

错误如下:

put(String, capture#2-of ? extends A)类型中的方法Multimap<String,capture#2-of ? extends A>不适用于参数(String, B)

我应该可以添加一个Bsince Bextends A。但我做不到。

4

2 回答 2

2

If you mean a multimap from String to objects of type A or any subtype of A, then that's a Multimap<String, A>. If you mean a multimap from String to objects of some specific but unknown subtype of A, then that's a Multimap<String, ? extends A>.

于 2013-04-25T19:02:49.650 回答
0

You can not add values to order, because they key is

? extends A

and compiler doesn't know the lower bound type.

于 2013-04-25T19:02:26.877 回答