java 在一个方法中返回一个泛型变量

今天写了一个返回泛型的方法:

public <T> T returnTypeList(String type){
		
		T t=null;
		
		switch(type){
		
		case "film":
			t=(T) film;
			break;
		case "audio":
			t=(T) audio;
			break;
		case "word":
			t=(T) word;
			break;
		case "img":
			t=(T) img;
			break;
		case "jar":
			t=(T) jar;
			break;
		case "excal":
			t=(T) excal;
			break;
		case "ppt":
			t=(T) ppt;
			break;
		case "pdf":
			t=(T) pdf;
			break;
			
		}
		
		return t;
	}

 其中,jar和pdf是字符串,其他返回类型都是List

猜你喜欢

转载自1015786613.iteye.com/blog/2234698