a-foundation/src/main/java/com/ajjpj/afoundation/collection/immutable/JavaUtilMapWrapper.java
@Override
    public Set<K> keySet() {
        return new AbstractSet<K>() {
            @Override
            public Iterator<K> iterator() {
                return new Iterator<K>() {
                    final Iterator<AMapEntry<K,V>> it = inner.iterator();

                    @Override
                    public boolean hasNext() {
                        return it.hasNext();
                    }

                    @Override
                    public K next() {
                        return it.next().getKey ();
                    }

                    @Override
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }

            @Override
            public int size() {
                return inner.size();
            }
        };
    }
@Override
    public Set<K> keySet() {
        return new AbstractSet<K>() {
            @Override
            public Iterator<K> iterator() {
                return new Iterator<K>() {
                    final Iterator<AMapEntry<K,V>> it = inner.iterator();

                    @Override
                    public boolean hasNext() {
                        return it.hasNext();
                    }

                    @Override
                    public K next() {
                        return it.next().getKey ();
                    }

                    @Override
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }

            @Override
            public int size() {
                return inner.size();
            }
        };
    }
@ Override public Set < K > keySet ( ) { return new AbstractSet < K > ( ) { @ Override public Iterator < K > iterator ( ) { return new Iterator < K > ( ) { final Iterator < AMapEntry < K , V > > it = inner . iterator ( ) ; @ Override public boolean hasNext ( ) { return it . hasNext ( ) ; } @ Override public K next ( ) { return it . next ( ) . getKey ( ) ; } @ Override public void remove ( ) { throw new UnsupportedOperationException ( ) ; } } ; } @ Override public int size ( ) { return inner . size ( ) ; } } ; }
There is usually a performance gain to be had by overriding this default implementation
There is usually a performance gain to be had by overriding this default implementation