Function<T,R>函数型接口</T,R>

  • 传入T类型参数,返回R类型值

Consumer< T>:消费型接口

  • 传入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;
       });
       }

/** * Function 函数是接口,有参数,有返回值 * * @param t T * @param function Function * @return R */
   public static <T, R> R functionMethod(T t, Function<T, R> function) {
       return function.apply(t);
   }
   
   /** * BiFunction 函数是接口,有参数,有返回值 * * @param t T * @param u U * @param biFunction BiFunction * @param <T> T * @param <U> U * @param <R> R * @return R */
   public static <T, U, R> R biFunctionMethod(T t, U u, BiFunction<T, U, R> biFunction) {
       return biFunction.apply(t, u);
   }

    /** * Consumer 消费型接口,有参数,无返回值 * * @param person Person * @param consumer Consumer */
public static void consumerMethod(Person person, Consumer<Person> consumer) {
 consumer.accept(person);
}

   /** * Consumer 消费型接口,有参数,无返回值 * * @param person Person * @param people People * @param biConsumer BiConsumer */
   public static void biConsumerMethod(Person person, People people, BiConsumer<Person, >People> biConsumer) {
       biConsumer.accept(person, people);
   }

详见githab