Iterable<Entry<K>> () { return () -> { ObjectIterator<Object2IntMap.Entry<MyReference<K>>> tIterator = myMap.object2IntEntrySet().iterator(); return ContainerUtil.filterIterator(new Iterator<Entry<K>>() { @Override public boolean hasNext() { return tIterator.hasNext(); } @Override public void remove() { throw new UnsupportedOperationException(); } @Override public Entry<K> next() { Object2IntMap.Entry<MyReference<K>> entry = tIterator.next(); return new Entry<K>() { @Override public @NotNull K getKey() { K v = SoftReference.dereference(entry.getKey()); //noinspection unchecked return v == null ? (K)GCED : v; } @Override public int getValue() { return entry.getIntValue(); } }; } }, o -> o.getKey() != GCED); }; }