kok*_*ing 3 java collections identity multimap guava
Java提供了IdentityHashMap,当您想要通过==而不是equals方法来比较对象时,它是完美的.
番石榴提供了良好的包装器Map<Key, Set<Value>是SetMultimap.但是没有使用身份对象比较(==)的实现.
有什么比平原更好的
 IdentityHashMap<Key, IdentityHashSet<Value>>吗?有些人IdentitySetMultimap<Key, Value>会很理想.
你可以用Multimaps.newSetMultimap(Map, Supplier)与Maps.newIdentityHashMap()和Sets.newIdentityHashSet():
public static <K, V> SetMultimap<K, V> newIdentitySetMultimap() {
    return Multimaps.newSetMultimap(Maps.newIdentityHashMap(), Sets::newIdentityHashSet);
}
Run Code Online (Sandbox Code Playgroud)
这还使您能够通过指定不同的映射或集实现来仅对键使用标识比较,或仅使用值.上面的示例将使用两者的身份比较.