gpt4 book ai didi

java - Apex:map.Put() byVal 而不是 byRef?

转载 作者:行者123 更新时间:2023-12-01 22:28:18 24 4
gpt4 key购买 nike

我想知道是否有办法通过值而不是引用将元素 .put() 到映射中。

我有一个 map >和一个填充它的循环,如下所示:

    Map<string,List<string>> result = new Map<string,List<string>>();
List<string> temp = new list<string>();

for(CustomObj__c i:customList){
for(CustomObj__c j:customList2){
if(j.id == i.id){
temp.add(j.Contact__r.Owner.Id);
temp.add(j.Contact__r.Id);
result.put(i.Deal__r.id, temp);
temp.clear();
break;
}
}
}

问题是当我清除临时列表时。然后我最终得到一个包含键但列表值为空的映射。是否可以在 map 中按值 .put() 列表(创建副本),使其不受调用 temp.clear() 的影响?

谢谢大家,

扎克

最佳答案

您可以像这样修改您的代码。在此代码中,我为每个 map 插入创建一个新实例。

map > 结果 = 新 map >(); 列出温度;

for(CustomObj__c i:customList){
for(CustomObj__c j:customList2){
if(j.id == i.id){
temp = new list<string>();
temp.add(j.Contact__r.Owner.Id);
temp.add(j.Contact__r.Id);
result.put(i.Deal__r.id, temp);
break;
}
}
}

关于java - Apex:map.Put() byVal 而不是 byRef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28303465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com