通过java反射技术获取泛型的真实类型并对其实例化

public DaoBaseInterfaceImpl()
	{
		// 反射得到T的真实类型
		ParameterizedType ptype = (ParameterizedType) this.getClass().getGenericSuperclass();// 获取当前new的对象的泛型的父类的类型
		this.clazz = (Class<T>) ptype.getActualTypeArguments()[0]; // 获取第一个类型参数的真实类型model = clazz.newInstance();实例化需要的时候添加
	}

你可能感兴趣的:(反射)