What are functional interfaces used for in Java 8?

前端 未结 10 2247
Happy的楠姐
Happy的楠姐 2020-11-22 09:08

I came across a new term in Java 8: "functional interface". I could only find one use of it while working with lambda expressions.

Java 8 provides

10条回答
  •  执笔经年
    2020-11-22 10:05

    A lambda expression can be assigned to a functional interface type, but so can method references, and anonymous classes.

    One nice thing about the specific functional interfaces in java.util.function is that they can be composed to create new functions (like Function.andThen and Function.compose, Predicate.and, etc.) due to the handy default methods they contain.

提交回复
热议问题