package com.lm; import org.junit.Test; import java.util.function.Function; /** * * Consumer<T> :消费型接口 * void accept(T t) : * * Supplier <T> : 供给型接口 * T get(); * * Function<T,R> :函数型接口 * R apply(T t); * * Predicate<T> : 断言型接口 * boolean test(T t) * */ public class TestLambda12 { @Test public void test1() { String newStr = strHandler("/t/t/t hello world ",(str) -> str.trim());//去首尾空格 System.out.println(newStr); System.out.println("--------------------------"); String newStr2 = strHandler("/t/t/t hello world ",(str) -> str.toUpperCase());//转大写 System.out.println(newStr2); } //需求: 用于处理字符串 //Function<T,R> :函数型接口 public String strHandler(String str , Function<String ,String> fun){ return fun.apply(str); } }