java泛型方法, 爽

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);
    }
}

猜你喜欢

转载自1971161579.iteye.com/blog/2406734