以下代码片段取自 Commons 框架的 CollectionUtils.java 文件:
private static class CardinalityHelper<O> {
final Map<O, Integer> cardinalityA, cardinalityB;
public CardinalityHelper(final Iterable<? extends O> a,
final Iterable<? extends O> b) {
cardinalityA = CollectionUtils.<O> getCardinalityMap(a);
cardinalityB = CollectionUtils.<O> getCardinalityMap(b);
}
public final int max(final Object obj) {
return Math.max(freqA(obj), freqB(obj));
}
public final int min(final Object obj) {
return Math.min(freqA(obj), freqB(obj));
}
public int freqA(final Object obj) {
return getFreq(obj, cardinalityA);
}
public int freqB(final Object obj) {
return getFreq(obj, cardinalityB);
}
private final int getFreq(final Object obj,
final Map<?, Integer> freqMap) {
final Integer count = freqMap.get(obj);
if (count != null) {
return count.intValue();
}
return 0;
}
}
getCardinalityMap 返回<O> Map<O, Integer>
有人可以帮我理解吗
- 是什么
cardinalityA = CollectionUtils.<O> getCardinalityMap(a);
意思?这是某种类型转换吗? - 返回类型是什么
<O> Map<O, Integer>
意思? - 这个技巧叫什么?
谢谢