【java开发】泛型工厂

//泛型工厂
public class DaoFactory {

	private DaoFactory(){}
	private static final DaoFactory instance = new DaoFactory();
	public static DaoFactory getInstance(){
		return instance;
	}
	
	public <T> T createDao(String className,Class<T> clazz){
		try {
			return (T) Class.forName(className).newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		} 
	}
	
}


"反射,就是把Java类中的各种成分映射成相应的Java类"。-------------------------这句话比好多书上的讲解都要精辟、透彻!赞!!

你可能感兴趣的:(【java开发】泛型工厂)