creates a specialized copy of the given instance
@param specializedClass target specialized class to create an instance of
@param t the object to copy and specialize
@return the specialized instance. Should be functionally equivalent to t
770067
private Object specializeInstance(ClassDescriptor specializedClass, Object t) {
    try (Logger l = new Logger("specializeInstance(" + specializedClass.getSpecializedClass().getSimpleName() + " , " + t + ")")) {
      if (!specializedClass.isSpecialized()) {
        l.log("value unchanged");
        return t;
      }
      l.log("Creating new instance");
      Object newInstance = specializedClass.getSpecializedClass().newInstance();
      l.log("setting field values:");
      Class<?> c = t.getClass();
      l.log("from class " + c.getSimpleName() + " to class " + specializedClass.getSpecializedClass().getSimpleName());
      while (c != null && specializedClass != null) {
        for (Field field : c.getDeclaredFields()) {
          field.setAccessible(true);
          Object value = field.get(t);
          FieldDescriptor fieldDescriptor = specializedClass.getFields().get(field.getName());
          if (fieldDescriptor != null && fieldDescriptor.getSpecializedClass().isSpecialized()) {
            value = specializeInstance(fieldDescriptor.getSpecializedClass(), value);
            l.log("- specialized " + newInstance.getClass().getSimpleName() + "." + field.getName() + " = " + value);
          } else {
            l.log("- copied " + newInstance.getClass().getSimpleName() + "." + field.getName() + " = " + value);
          }
          Field newField = newInstance.getClass().getField(field.getName());
          newField.set(newInstance, value);
        }
        c = c.getSuperclass();
        specializedClass = specializedClass.getParent();
      }
      return newInstance;
    } catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
      throw new SpecializationException("Could not create instance of the specialized class " + specializedClass.specializedClass.getSimpleName(), e);
    }
  }
209182
@SuppressWarnings("unchecked")
    public static <T> T createProxyObject(Class<T> proxyClass) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(proxyClass);
        enhancer.setCallback(new InvokeInterceptor(proxyClass));
        return (T) enhancer.create();
    }
1031020
public static <T> T newInstance(Class<T> type) {
        try {
            return type.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
89419
public static <T> T createInstanceForGenericClass(Object parent) {
		try {
			Object instance = getGenericClassFromParent(parent).newInstance();
			return (T) instance;
		} catch (InstantiationException | IllegalAccessException e) {
			JK.throww(e);
		}
		return null;
	}
1070448
public static <T, K extends Collection<T>> JavaType createCollectionType(Class<K> k,
                                                                             Class<T> t) {
        BaseType collectionType = new BaseType();
        BaseType genericType = new BaseType();
        genericType.setType(t);
        JavaType[] generics = { genericType };
        collectionType.setType(k);
        collectionType.setGenerics(generics);
        return collectionType;
    }
788468
@SuppressWarnings("unchecked")
  public static <Type extends Message> RpcCallback<Type>
  specializeCallback(final RpcCallback<Message> originalCallback) {
    return (RpcCallback<Type>)originalCallback;
    // The above cast works, but only due to technical details of the Java
    // implementation.  A more theoretically correct -- but less efficient --
    // implementation would be as follows:
    //   return new RpcCallback<Type>() {
    //     public void run(Type parameter) {
    //       originalCallback.run(parameter);
    //     }
    //   };
  }
1168306
public static <T extends Entity<ID>, ID extends Serializable> T newInstance(Class<T> clazz, ID id) {
    return meta.newInstance(clazz, id);
  }
882491
public T newInstance() {
        try {
            return getEnhancedClass().newInstance();
        } catch (Exception e) {
            logger.error("Could not instantiate enhanced object.", e);

            throw ExceptionUtil.propagate(e);
        }
    }
277110
@SneakyThrows
    @SuppressWarnings("unchecked")
    public static <T extends ShardingAlgorithm> T newInstance(final String shardingAlgorithmClassName, final Class<T> superShardingAlgorithmClass) {
        Class<?> result = Class.forName(shardingAlgorithmClassName);
        if (!superShardingAlgorithmClass.isAssignableFrom(result)) {
            throw new ShardingException("Class %s should be implement %s", shardingAlgorithmClassName, superShardingAlgorithmClass.getName());
        }
        return (T) result.newInstance();
    }
343431
public static <T> T newInstance(final Class<T> clazz) {
        try {
            return clazz.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new ClassApiException(e);
        }
    }
145780
@SuppressWarnings("unchecked")
	public <T> T toProxyBean(Class<T> interfaceClass) {
		return (T) Proxy.newProxyInstance(ClassLoaderUtil.getClassLoader(), new Class<?>[]{interfaceClass}, this);
	}
987001
@SuppressWarnings("unchecked")
  public <T extends Entity<?>> T newInstance(final Class<T> clazz) {
    return (T) getEntityType(clazz).newInstance();
  }
1186311
public T copy() {
        T copy = Instantiator.of(type).instantiate();
        return copyInto(copy);
    }
1164178
public static <T> T newInstance(Class<T> class1) {
		try {
			return class1.newInstance();
		} catch (Exception e) {
			throww(e);
			return null;
		}
	}
617241
public <T extends InteractionAwareFixture> T create(Class<T> clazz) {
        return create(clazz, null, null);
    }
141249
public static <T> SuperclassIterable<T> of(Class<T> type) {
        return new SuperclassIterable<>(type, false);
    }
365468
static <T extends Com4jObject>
    T create( Class<T> primaryInterface, long ptr ) {
        Wrapper w = new Wrapper(ptr);
        T r = primaryInterface.cast(Proxy.newProxyInstance(
            primaryInterface.getClassLoader(),
            new Class<?>[]{primaryInterface},
                w));
        return r;
    }