HashMapString MyInfoWindow infoWindowMap = new HashMap; if infoWindowMapgetbeangetDatagetTargetId!= null infoWindowMapgetbeangetDatagetTargetIdclose;
在上述代码中,对于infoWindowMap的移除操作可能存在问题。
首先,代码中使用了infoWindowMap.get(bean.getData().getTargetId())多次调用,这可能导致多次访问和查询HashMap,可以将其存储在一个临时变量中,避免多次查询:
String targetId = bean.getData().getTargetId();
MyInfoWindow infoWindow = infoWindowMap.get(targetId);
if (infoWindow != null) {
// 移除操作
}
其次,移除操作部分的代码存在问题。在移除操作中,应该使用targetId作为参数进行移除,而不是使用infoWindowMap.get(bean.getData().getTargetId())作为参数。修改后的代码如下:
String targetId = bean.getData().getTargetId();
MyInfoWindow infoWindow = infoWindowMap.get(targetId);
if (infoWindow != null) {
infoWindow.close();
infoWindow.onDetach();
infoWindowMap.remove(targetId);
}
这样可以确保移除操作正确执行,并且移除干净
原文地址: http://www.cveoy.top/t/topic/hH0e 著作权归作者所有。请勿转载和采集!