zoukankan      html  css  js  c++  java
  • Starter Set of Functional Interfaces

    Java Development Kit 8 has a number of functional interfaces. Here we review the starter set—the interfaces we frequently encounter and need to first get familiar with. All the interfaces we see here are part of the java.util.function package.

    Consumer<T>

    Description

    Represents an operation that will accept an input and returns nothing. For this to be useful, it will have to cause side effects.

    Abstract method

    accept()

    Default method(s)

    andThen()

    As a parameter to the forEach() method

    Primitive specializations

    IntConsumer, LongConsumer, DoubleConsumer, …

    Supplier<T>

    Description

    A factory that’s expected to return either a new instance or a precreated instance

    Abstract method

    get()

    Default method(s)

    To create lazy infinite Streams and as the parameter to the Optional class’s orElseGet() method

    Primitive specializations

    IntSupplier, LongSupplier, DoubleSupplier, …

    Predicate<T>

    Description

    Useful for checking if an input argument satisfies some condition

    Abstract method

    test()

    Default method(s)

    and(), negate(), and or()

    As a parameter to Stream’s methods, like filter() and anyMatch()

    Primitive specializations

    IntPredicate, LongPredicate, DoublePredicate, …

    Function<T, R>

    Description

    A transformational interface that represents an operation intended to take in an argument and return an appropriate result

    Abstract method

    apply()

    Default method(s)

    andThen(), compose()

    As a parameter to Stream’s map() method

    Primitive specializations

    IntFunction, LongFunction, DoubleFunction, IntToDoubleFunction, DoubleToIntFunction, …

  • 相关阅读:
    将光标定位于输入框最右侧的实现方式
    Canvas学习笔记
    CSS3 颜色模式
    CSS ^ $选择器
    jQuery.Validator Sample
    让网页的title动起来
    转:线程间操作无效: 从不是创建控件“”的线程访问它~~~的解决方法~
    winform 表单正则表达式验证 示例(ValidationRule)
    详解用Navicat工具将Excel中的数据导入Mysql中
    PHP面试题之实现输出100以内的质数
  • 原文地址:https://www.cnblogs.com/coderland/p/5902763.html
Copyright © 2011-2022 走看看