Function<T,R>函数型接口</T,R>
Consumer< T>:消费型接口
例 :
public static void main(String[] args) {
People people3 = functionMethod(person, p -> {
People people2 = constructor(People::new);
people2.setName(p.getName());
people2.setSex(p.getSex());
return people2;
});
}
public static <T, R> R functionMethod(T t, Function<T, R> function) {
return function.apply(t);
}
public static <T, U, R> R biFunctionMethod(T t, U u, BiFunction<T, U, R> biFunction) {
return biFunction.apply(t, u);
}
public static void consumerMethod(Person person, Consumer<Person> consumer) {
consumer.accept(person);
}
public static void biConsumerMethod(Person person, People people, BiConsumer<Person, >People> biConsumer) {
biConsumer.accept(person, people);
}
详见githab