java返回泛型_Java返回泛型的方法-实例

  • Post author:
  • Post category:java

package com.frank.app;

import java.io.UnsupportedEncodingException;

import java.lang.reflect.Type;

import java.net.URLEncoder;

import java.util.LinkedList;

import java.util.List;

public class App {

private static List demo1(Class clazz) {

T obj = null;

try {

obj = clazz.newInstance();

} catch (InstantiationException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

List result = new LinkedList();

result.add(obj);

return result;

}

public static void main(String[] args) {

List list = demo1(String.class);

System.out.println(list);

}

———————


版权声明:本文为weixin_42310558原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。