basicgenerator.java

来自「看thinkinjava学习java时」· Java 代码 · 共 25 行

JAVA
25
字号
package myutils;

public class BasicGenerator<T> implements Generator<T>{
	private Class<T> type;
	public BasicGenerator(Class<T> type){this.type = type;
	}
	public T next(){
		try{
		//Assumes type is a public class
		return type.newInstance();
	}catch(Exception e){
		throw new RuntimeException(e);
	}
	}

	//Produce a Default generator given a type token;
	 
	public static <T> Generator<T> create(Class<T> type) {
		return new BasicGenerator<T>(type);
		

	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?