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()

Popular usage

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)

Popular usage

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()

Popular usage

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()

Popular usage

As a parameter to Stream’s map() method

Primitive specializations

IntFunction, LongFunction, DoubleFunction, IntToDoubleFunction, DoubleToIntFunction, …

Starter Set of Functional Interfaces的更多相关文章

  1. Lambda Expressions and Functional Interfaces: Tips and Best Practices

    转载自https://www.baeldung.com/java-8-lambda-expressions-tips 1. Overview   Now that Java 8 has reached ...

  2. Functional Programming without Lambda - Part 1 Functional Composition

    Functions in Java Prior to the introduction of Lambda Expressions feature in version 8, Java had lon ...

  3. java functional syntax overview

    Defining a Functional Interface @FunctionalInterface public interface TailCall<T> { TailCall&l ...

  4. Java 中的函数式编程(Functional Programming):Lambda 初识

    Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...

  5. Chapter 7 -- Functional

    Caveats 说明 As of Java 7, functional programming in Java can only be approximated through awkward and ...

  6. 深入理解Java 8 Lambda(语言篇——lambda,方法引用,目标类型和默认方法)

    作者:Lucida 微博:@peng_gong 豆瓣:@figure9 原文链接:http://zh.lucida.me/blog/java-8-lambdas-insideout-language- ...

  7. Java资源大全中文版(Awesome最新版)

    Awesome系列的Java资源整理.awesome-java 就是akullpp发起维护的Java资源列表,内容包括:构建工具.数据库.框架.模板.安全.代码分析.日志.第三方库.书籍.Java 站 ...

  8. Java 8新特性-1 函数式接口

    Java 8 引入的一个核心概念是函数式接口(Functional Interfaces). 通过在接口里面添加一个抽象方法,这些方法可以直接从接口中运行. 如果一个接口定义个唯一一个抽象方法,那么这 ...

  9. JDK各个版本的新特性jdk1.5-jdk8

    JDK各个版本的新特性 对于很多刚接触java语言的初学者来说,要了解一门语言,最好的方式就是要能从基础的版本进行了解,升级的过程,以及升级的新特性,这样才能循序渐进的学好一门语言.今天先为大家介绍一 ...

随机推荐

  1. linux中改变文件权限和属性

    Linux中,默认显示所有用户名的文件在/etc/passwd,用户组的信息在/etc/group 密码/etc/shadow chgrp改变文件所属用户组 chgrp [-R] 用户组名 文件或目录 ...

  2. UVa 12716 (GCD == XOR) GCD XOR

    题意: 问整数n以内,有多少对整数a.b满足(1≤b≤a)且gcd(a, b) = xor(a, b) 分析: gcd和xor看起来风马牛不相及的运算,居然有一个比较"神奇"的结论 ...

  3. dict 字典

    Python 学习笔记[dict的操作方法] Python中dict详解

  4. 【C#学习笔记】函数重载

    using System; namespace ConsoleApplication { class Program { static void Print(int a, int b) { Conso ...

  5. LwIP编译方法以及选项说明

    条件编译命令 作用说明 IP_SOF_BROADCAST   LWIP_IGMP  

  6. c# 利用反射动态给实体类对象赋值

    转:http://blog.sina.com.cn/s/blog_659a572b0100xp5s.html 例子如下 using System; using System.Collections.G ...

  7. hdu 1573 x问题(中国剩余定理)HDU 2007-1 Programming Contest

    只是套模板而已(模板其实也不懂). 留着以后好好学的时候再改吧. 题意—— X = a[i] MOD b[i]; 已知a[i],b[i],求在[1, n]中存在多少x满足条件. 输入—— 第一行一个整 ...

  8. CSS常用十大技巧

    技巧1  去掉网页超链接的下划线 去掉网页超链接的下划线,在<head>与</head>之间相应的位置输入以下代码. <style type="text/css ...

  9. ASP.NET导出excel表方法汇总

    asp.net里导出excel表方法汇总  1.由dataset生成 public void CreateExcel(DataSet ds,string typeid,string FileName) ...

  10. ASP.NET开发在JavaScript有中文汉字时出现乱码时简单有效的解决

    一般情况在使用ASP.NET开发使用JavaScript有中文汉字时不会出现乱码情况,比如:alert('您看到我了吗?');这样直接输入中文汉字的代码中是不会出现乱码的,如果出现了,一是检查Web. ...