Map value类型不同的写法

Map value类型不同的写法
Map<String, Object> accountMap=new HashMap<String, Object>();
int userId = data.get("userId").getAsInt();
int accType = data.get("accType").getAsInt();

String name =  data.get("accType").getAsString();

accountMap.put("userId",userId);
accountMap.put("accType",accType);

accountMap.put("name ",name );




Integer userId= (Integer) accountMap.get("userId");
String name = (String) accountMap.get("name");
要么强制转换,要么value只能存一种类型

 

posted @ 2017-05-15 19:14  Rainyn  阅读(3381)  评论(0编辑  收藏  举报