004 内置函数式接口

一 . 概述

  在前面,我们了解到了什么是函数式接口,也知道了一个lambda表达式如果能够执行的话,一定需要一个函数式接口.

  当我们使用了泛型的情况下,我们发现这些函数式接口从一定程度上说都是相同的.

  因此,在jdk之中为我们提供了一定数量的函数式接口.


二 . 内置的函数式接口

[1]消费接口-->Consumer

  该接口拥有一个参数,没有返回值.

public interface Consumer<T> {
    void accept(T t);

[2]生产者接口--->Supplier

  该接口没有入参,并有用返回值.

public interface Supplier<T> {
    T get();
}

[3]函数式接口 --->Function

  该接口包含一个入参且拥有返回值

public interface Function<T, R> {

    R apply(T t);

[4]断言式接口--->

public interface Predicate<T> {

    boolean test(T t);

  一个入参,且返回值为boolean


猜你喜欢

转载自www.cnblogs.com/trekxu/p/9397850.html
004
今日推荐