我错过了什么?为什么在下面要使用
Object::toString
而不是 Integer::toString
?这与泛型的类型擦除有关吗?Arrays.asList(1,2,3).stream().map(Integer::toString).forEach(System.out::println); //Won't compile
Arrays.asList(1,2,3).stream().map(Object::toString).forEach(System.out::println); //Compiles and runs fine
Arrays.asList(1,2,3).forEach(System.out::println);
或Stream.of(1,2,3).forEach(System.out::println);
或IntStream.rangeClosed(1, 3).forEach(System.out::println);
。 - Peter Lawrey