<p> THAT'S OK: ${((Map<String,Integer>)view.get("upgrade_assignment_type_map")).toString()} </p>
<p> THAT'S ALSO OK:
for( String _name : ((Map<String, Integer>)view.get("upgrade_assignment_type_map")).keySet() ) {
<p> ${_name}: ${((Map<String, Integer>)view.get("upgrade_assignment_type_map")).get(_name)} </p>
}
</p>
<br><br>
<p> SADLY THAT'S NOT OK::: ${((Map<String, Integer>)view.get("upgrade_assignment_type_map")).get("MANUAL")} </p>
上面的代码段打印出以下输出,这让我感到惊讶:
THAT'S OK: {AUTO_WITH_BALANCE_EMPHASIS=2, AUTO_WITH_OFFENSIVE_EMPHASIS=0, MANUAL=3, AUTO_WITH_DEFENSIVE_EMPHASIS=1}
THAT'S ALSO OK:
AUTO_WITH_BALANCE_EMPHASIS: 2
AUTO_WITH_OFFENSIVE_EMPHASIS: 0
MANUAL: 3
AUTO_WITH_DEFENSIVE_EMPHASIS: 1
SADLY THAT'S NOT OK:::
代码段的最后一行尝试获取键“MANUAL”的值,但它没有打印该值,如果我尝试将其转换为 toString(如${((Map<String, Integer>)view.get("upgrade_assignment_type_map")).get("MANUAL").toString()}
),它在运行时给我 null。我不明白为什么会这样?
<p> ${_name}: ${_name.length()} : ${((Map<String, Integer>)view.get("upgrade_assignment_type_map")).get(_name)} </p>
当我打印我得到的每个键的长度(在第一个冒号之后)时:
AUTO_WITH_BALANCE_EMPHASIS: 29 : 2
AUTO_WITH_OFFENSIVE_EMPHASIS: 29 : 0
MANUAL: 10 : 3
AUTO_WITH_DEFENSIVE_EMPHASIS: 30 : 1
注意:我在 java 源代码中创建地图为Map<String, Integer> nameToTypeMap = Maps.newHashMap();