public class MyTest { @Test public void testMethodGenerics() throws Exception { List<Integer> list = getMapValue("b"); list.stream().forEach(System.out::println); System.out.println((String) getMapValue("a")); } private <T> T getMapValue(String key){ Map<String,Object> map = Maps.newHashMap(); map.put("a","Sting"); map.put("b",Arrays.asList(1,2,34)); return (T) map.get(key); } }
java泛型方法, 爽
猜你喜欢
转载自1971161579.iteye.com/blog/2406734
今日推荐
周排行