java8新特新-内建函数式接口
package newJava8;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
/**
* 内建函数式接口
* 函数式编程提供的内在接口 java.util.function
* 核心接口:
* 1)功能性接口: interface Function<T,R></>
* 2)供给型接口: interface Supplier<T></>
* 3)消费型接口: interface Consumer<T></>
* 4)断言型接口: interface Predict<T></>
*/
public class NewInnerReference {
public static void main(String args[]){
Function<Integer,String>fun1=String::valueOf;
System.out.println(fun1.apply(7));
Supplier<String>fun2="hello"::toUpperCase;
System.out.println(fun2.get());
Consumer<String>fun3=System.out::print;
fun3.accept("消费型接口");
Predicate<String> fun4="eef"::endsWith;
System.out.println(fun4.test("f"));
//测试结果
// 7
// HELLO
// 消费型接口true
}
}