最近用到的一个java方法泛型

	/**
	 * 根据指定的类型(targetClazz)实例化一个bean,并将source bean的属性赋值给实例化的bean
	 * 
	 * @param source
	 * @param targetClazz
	 * @return
	 */
	public static <T> T beanUtils(Object source, Class<T> targetClazz) {
		T target = null;
		try {
			target = targetClazz.newInstance();
		} catch (Exception e) {
			throw new RuntimeException("实例化" + targetClazz + "失败!");
		}
		BeanUtils.copyProperties(source, target);
		return target;
	}

你可能感兴趣的:(java,bean)