2013-06-25 52 views
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,但我得到了一个错误。

我也跟着link从哪里我知道我做错了,但可以找到出路。在对应于section is char数据库和值的standard is Integer

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); 
    } 

这里实际值。我给所有这些值作为字符串,我需要将它们存储在HashTable中,所以我想要一些原始的哈希表,将保存所有这些值。没有类型是用户定义的

+3

目前还不清楚现有的代码看起来像什么,或者你想以后用表做(或者为什么你不使用'HashMap')什么 –

+0

我增加了一些更多的描述,我希望这将清除我的问题 –

+0

不是真的 - 我们不知道任何涉及的类型。例如,“Appconstants.Col_studentinfo_S_Section”是什么? –

回答

1

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

HashTable<String, HashTable<String, Object>>