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 generic method, cool
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326392282&siteId=291194637
Recommended
Ranking