docs: @SuppressWarnings("unchecked")
      public static <T> T asType(Collection col, Class<T> clazz) {
          if (col.getClass() == clazz) {
              return (T) col;
          }
          if (clazz == List.class) {
              return (T) asList((Iterable) col);
          }
          if (clazz == Set.class) {
              if (col instanceof Set) return (T) col;
              return (T) new LinkedHashSet(col);
          }
          if (clazz == SortedSet.class) {
              if (col instanceof SortedSet) return (T) col;
              return (T) new TreeSet(col);
          }
          if (clazz == Queue.class) {
              if (col instanceof Queue) return (T) col;
              return (T) new LinkedList(col);
          }
          if (clazz == Stack.class) {
              if (col instanceof Stack) return (T) col;
              final Stack stack = new Stack();
              stack.addAll(col);
              return (T) stack;
          }
  
          if (clazz!=String[].class && ReflectionCache.isArray(clazz)) {
              try {
                  return (T) asArrayType(col, clazz);
              } catch (GroovyCastException e) {
                  /* ignore */
              }
          }
  
          Object[] args = {col};
          try {
              return (T) InvokerHelper.invokeConstructorOf(clazz, args);
          } catch (Exception e) {
              // ignore, the constructor that takes a Collection as an argument may not exist
          }
          if (Collection.class.isAssignableFrom(clazz)) {
              try {
                  Collection result = (Collection) InvokerHelper.invokeConstructorOf(clazz, null);
                  result.addAll(col);
                  return (T)result;
              } catch (Exception e) {
                  // ignore, the no arg constructor might not exist.
              }
          }
  
          return asType((Object) col, clazz);
      }