0

尝试创建通用 HashTable 时出现以下错误。

The method put(String, capture#2-of ?) in the type Hashtable<String,capture#2-of ?> is not applicable for the arguments (String, int)

我需要一个哈希表,如下所示: HashTable<String, HashTable<String, AnyWrapperType>>

by AnyWrapperType i mean it could be Integer or String or Character or Boolean

我用过?AnyWrapperType但我得到了一个错误。

我也从我知道我做错了什么但可以找到出路的地方点击链接。

    Hashtable<String, Hashtable<String, String>> paramTocol = new Hashtable<>();

    if (standard != null && (!standard.isEmpty())) {
        Hashtable<String, String> temp = new Hashtable<>();
        temp.put(Appconstants.Col_studentinfo_S_Class,
                AvailableClass.getValueByName(standard));
        paramTocol.put("standard", temp);
    }
    if (section != null && (!section.isEmpty())) {
        Hashtable<String, String> temp = new Hashtable<>();
        temp.put(Appconstants.Col_studentinfo_S_Section, section);

        paramTocol.put("section", temp);
    }

这里standard is Integer数据库中的实际值和对应的值 section is char。我将所有这些值作为字符串给出,我需要将它们存储在 HashTable 中,所以我想要一些原始的哈希表来保存所有这些值。没有一个类型是用户定义的

4

1 回答 1

1

我认为您可以将其设置AnyWrapperTypeObject. 由于 java 中的所有类都是 Object 的直接或间接子类,因此您可以将类型设置为 Object,而不是设置泛型类型。当您需要获取该元素时,您应该执行type-cast.

HashTable<String, HashTable<String, Object>>
于 2013-06-30T12:07:27.743 回答