Apex里面的retainAll
学习目的
1,掌握集合retainAll的用法
2,避免幽灵bug
集合retainAll的用法
1,Boolean retainAll(List/Set)
该方法的作用相信很多人会认为是两个集合取交集。那真的是这样吗?在揭晓谜底之前,先来几道题目。
Set<String> cmpPartnerTypeSet = new Set<String>{'A','B'};
Set<String> cmpincentivePagramSet = new Set<String>{'A','B'};
System.debug('===='+cmpPartnerTypeSet.retainAll(cmpincentivePagramSet));
输出:false
这个时候肯定心里会说上一句:Fuck!预期的true呢?
那再来一道题目:
Set<String> cmpPartnerTypeSet = new Set<String>{'A','B'};
Set<String> cmpincentivePagramSet = new Set<String>{'B'};
S