public static <T>Collection<T> makeImmutable(Collection<T> mutableCollection){
  Collection<T> newCollection;
  try {
    @SuppressWarnings("unchecked") Class<Collection<T>> cls=(Class<Collection<T>>)mutableCollection.getClass();
    newCollection=cls.newInstance();
  }
 catch (  InstantiationException|IllegalAccessException e) {
    throw new IllegalStateException(e);
  }
  for (  T element : mutableCollection) {
    newCollection.add(Utils.makeImmutable(element));
  }
  return Collections.unmodifiableCollection(newCollection);
}

public static < T > Collection < T > makeImmutable ( Collection < T > mutableCollection ) { Collection < T > newCollection ; try { @ SuppressWarnings ( "unchecked" ) Class < Collection < T > > cls = ( Class < Collection < T > > ) mutableCollection . getClass ( ) ; newCollection = cls . newInstance ( ) ; } catch ( InstantiationException | IllegalAccessException e ) { throw new IllegalStateException ( e ) ; } for ( T element : mutableCollection ) { newCollection . add ( Utils . makeImmutable ( element ) ) ; } return Collections . unmodifiableCollection ( newCollection ) ; }
a recursive call to make a collection and all it ' s values immutable .
