我有以下代码(java se 6):

import org.javatuples.Pair;

final SortedMap<Pair<AbstractEnum<?>, String>, AdapterObject> myMap =
         new TreeMap<Pair<AbstractEnum<?>, String>();
myMap.put(Pair.with(SubTypeEnum.ITEM1, StringUtils.EMPTY), new AdapterObject());


AbstractEnum和SubTypeEnum只是:

public final class SubTypeEnum extends AbstractEnum<SubTypeEnum>
...
public abstract class AbstractEnum<T extends AbstractEnum<T>> implements Comparable<T>, Serializable


现在,编译器说:

The method put(Pair<AbstractEnum<?>,String>, AdapterObject) in the type Map<Pair<AbstractEnum<?>,String>,AdapterObject> is not applicable for the arguments (Pair<SubTypeEnum,String>, new AdapterObject())


有什么想法可以解决这个问题吗?

最佳答案

将声明更改为:

final SortedMap<Pair<? extends AbstractEnum<?>, String>, AdapterObject> myMap =
            new TreeMap<Pair<? extends AbstractEnum<?>,String>, AdapterObject>();

08-19 10:38