[英]Nested String HashMaps
I know I have the option to make a POJO object to store this. 我知道我可以选择创建一个POJO对象来存储它。 However, I am trying to do it in a nested HashMap. 但是,我试图在嵌套的HashMap中做到这一点。 Whenever I do the following I am getting Type Safety Warnings. 每当执行以下操作时,我都会收到“类型安全警告”。
Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
map.put("fund_cde", new HashMap(){{put("ABC", "ABC is not valid message.");}});
If I set the nested HashMaps type like so: 如果我像这样设置嵌套的HashMaps类型:
map.put("fund_cde", new HashMap<String, String>(){{put("ABC", "ABC is not valid message");}});
I end up with this warning instead: 我最终得到以下警告:
The serializable class does not declare a static final serialVersionUID field of type long 可序列化的类未声明类型为long的静态最终serialVersionUID字段
Any advice on correct way to do this? 关于正确方法的任何建议吗? I had a look at How to put/get values into/from Nested HashMap but I'm still not understanding it. 我看了一下如何在Nested HashMap中添加值或从中获取值,但我仍然不了解。
Thanks! 谢谢!
There is another way to achieve this if you like you can use because I also tried in different manner that also give warning.You can use this 如果您愿意的话,还有另一种方法可以实现此目的,因为我也尝试过以其他方式发出警告。您可以使用此方法
Map<String,String> map1=new HashMap<String,String>();
map1.put("ABC", "XYZ");
Map<String ,Object> map=new HashMap<String,Object>();
map.put("axz", map1);
If you really want to do away with the warning. 如果你真的想弄死警告。 Either include a version id like: 包括以下版本ID:
map.put("fund_cde", new HashMap(){
private static final long serialVersionUID = 1L;
{put("ABC", "ABC is not valid message.");}
});
or add the @SuppressWarnings("serial") annotation to the method. 或在方法中添加@SuppressWarnings(“ serial”)批注。 If you use an IDE like eclipse it can offer you these options as auto fixes. 如果您使用像eclipse这样的IDE,它可以为您提供这些选项作为自动修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.