import org.junit.Test;
import java.util.stream.IntStream;
public class GomanTest {
@Test
public void someTest() {
IntStream.of(2, 3, 1).collect(Container::new, Container::add, null);
}
}
class Container<T> {
void add(T t) {
System.out.println("this is container " + t);
}
}
输出:
this is container 2
this is container 3
this is container 1
这在 1.8.0_45.jdk 上成功运行。Container#add 如何转换为 ObjIntConsumer#accept?