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

标签 java dictionary salesforce apex

我想知道是否有办法通过值而不是引用将元素 .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/

相关文章:

java - 法语月份的第一个字母应该是大写使用java

python - 简化 `if...elif..else`条件

python - 计算Python字典中值的重复次数

python - 为什么在相同但以不同方式创建的嵌套字典中将值分配给键会导致不同的结果?

java - 十进制算术表达式的意外结果

java - 标准化 java 构造函数以供反射使用

salesforce - 如何在 Visualforce 页面上显示聚合 SOQL 查询的结果?

c# - 无法将数据发布到 UAT 服务器中的 Salesforce

java - Rest API 调用拒绝 Cookie

java.lang.LinkageError : loader constraint violation in interface itable initialization 错误