java stream generic

When calling stream, you must specify the generic type of the collection

        List list1 = Arrays.asList("1","2","3");
        list1.stream().filter(x->x.length()>=1).forEach(System.out::println);//报错,x被当成object来处理

To be changed to

        List<String> list1 = Arrays.asList("1","2","3");//指明集合类型是String
        list1.stream().filter(x->x.length()>=1).forEach(System.out::println);

Guess you like

Origin blog.csdn.net/claroja/article/details/113899273