我想用hashmap存储一个实体的属性。该值可以是内嵌的int
或String
的List
。什么是Java Hashmap的打字系统?
name : "John Smith"
attributes:
"seniority" : (int) 7
"tags" : List<String>("asst_prof","cs_dept")
"another_attrib" : (int) 3
我感到困惑的类型系统的地图,读书发散教程谷歌给出了。我最接近的是使用String
键和Object
值的东西。
问题:如何创建一个HashMap和插入的int
或List<String>
值,这样,当我取的值,这是类型转换(被标识为类型的成员)作为任一种int
或List<String>
,而不是Object
。
我依赖于Drools专家包,其中accesses values from maps by itself,所以类型为不在我的控制。
// Same as attributes.get("jsmith").isValid()
Person(attributes["jsmith"].valid)