如何解决有关Java Hashmap的Sonarqube错误
我有一个hashmap: 私有静态地图< string,jsonobject> LaserDatalist = new Hashmap< string,jsonobject>();
我写了代码的这一部分:
public void execute(jsonObject对象){jsonObject reportdata = laserdatalist.get(jsonutil.getAsjSonObject(object,object,loaontologykeys.print_document_id))); }
Sonar说此代码有问题: a Map< string,jsonObject>”不能在“字符串”类型中包含“ JSONOBJECT”
如何解决此错误?这个声纳信息是什么意思?
I have a hashMap :private static Map<String, JSONObject> laserDataList = new HashMap<String, JSONObject>();
I wrote this part of code :
public void execute(JSONObject object) {JSONObject reportData = laserDataList.get(JSONUtil.getAsJSONObject(object, LoanOntologyKeys.PRINT_DOCUMENT_ID)); }
Sonar says this code has problem : A "Map<String, JSONObject>" cannot contain a "JSONObject" in a "String" type
how can I resolve this bug ? what is the meaning of this sonar message ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从评论中,我可以看出您不了解问题。
您已经定义了一个地图对象。您已经指定了地图的键是类型字符串,并且值是类型的JSONOBJECT。
当您在地图中查找一个值时,您将“获取”方法传递给密钥类型的值,然后获得值类型的值。在这种情况下,再次,密钥类型为字符串,值类型为JSONOBJECT。您呼叫“ jsonutil.getasjsonobject()”所有返回jsonobject值,而不是字符串。
我不知道您的逻辑在做什么,但也许您需要这个:
I can see from the comments that you're not understanding the problem.
You've defined a Map object. You've specified that the keys of the map are of type String, and the values are of type JSONObject.
When you look up a value in a map, you pass to the "get" method a value of the KEY type, and you get back a value of the VALUE type. In this case, again, the key type is String, and the value type is JSONObject. Your calls to "JSONUtil.getAsJSONObject()" all return JSONObject values, not strings.
I don't know exactly what your logic is doing, but perhaps you need this: