【发布时间】:2013-06-25 18:51:57
【问题描述】:
我在尝试创建通用 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,如下所示:
HashTable<String, HashTable<String, AnyWrapperType>>
by AnyWrapperType i mean it could be Integer or String or Character or Boolean
我将? 用于AnyWrapperType,但出现错误。
我还关注了link,从那里我知道自己做错了什么,但可以找到出路。
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 中,所以我想要一些原始的哈希表来保存所有这些值。没有一个类型是用户定义的
【问题讨论】:
-
不清楚你现有的代码是什么样的,或者你之后试图对表格做什么(或者你为什么不使用
HashMap) -
我添加了更多描述,希望能解决我的问题
-
并非如此——我们不知道所涉及的任何类型。例如
Appconstants.Col_studentinfo_S_Section是什么? -
Appconstants.Col_studentinfo_S_Section是一个字符串,对应于数据库中的列名。 -
所以您的示例代码中的所有内容都是关于字符串的——包装器类型从何而来?如果您展示一个简短但 完整 程序(控制台应用程序),它实际上可以证明您的问题,那将非常有帮助。请阅读tinyurl.com/so-hints
标签: java collections hashtable