code: public Iterator iterator() {
          final MetaClass[] refs = metaClassInfo.toArray(EMPTY_METACLASS_ARRAY);
          
          return new Iterator() {
              // index in the ref array
              private int index = 0;
              // the current meta class
              private MetaClass currentMeta;
              // used to ensure that hasNext has been called
              private boolean hasNextCalled = false;
              // the cached hasNext call value
              private boolean hasNext = false;
  
              public boolean hasNext() {
                  if (hasNextCalled) return hasNext;
                  hasNextCalled = true;
                  if(index < refs.length) {
                      hasNext = true;
                      currentMeta = refs[index];
                      index++;
                  } else {
                      hasNext = false;
                  }
                  return hasNext;
              }
              
              private void ensureNext() {
                  // we ensure that hasNext has been called before 
                  // next is called
                  hasNext();
                  hasNextCalled = false;
              }
              
              public Object next() {
                  ensureNext();
                  return currentMeta;
              }
              
              public void remove() {
                  ensureNext();
                  setMetaClass(currentMeta.getTheClass(), currentMeta, null);
                  currentMeta = null;
              }
          };
      }
docs: Returns an iterator to iterate over all constant meta classes.
  This iterator can be seen as making a snapshot of the current state
  of the registry. The snapshot will include all meta classes that has
  been used unless they are already collected. Collected meta classes
  will be skipped automatically, so you can expect that each element
  of the iteration is not null. Calling this method is thread safe, the
  usage of the iterator is not.
  
  @return the iterator.