泛型方法

public class Test2 {

	public static <T> T getObject(Class<T> c) throws Exception{
		T t = c.newInstance();
		return t;
	}

	public static void main(String[] args) throws ClassNotFoundException, Exception{
		Object obj = getObject(Class.forName("test.Test2"));
		System.out.println(obj);
	}
}

你可能感兴趣的:(泛型,方法)