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()
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的更多相关文章
- 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 ...
- 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 ...
- java functional syntax overview
Defining a Functional Interface @FunctionalInterface public interface TailCall<T> { TailCall&l ...
- Java 中的函数式编程(Functional Programming):Lambda 初识
Java 8 发布带来的一个主要特性就是对函数式编程的支持. 而 Lambda 表达式就是一个新的并且很重要的一个概念. 它提供了一个简单并且很简洁的编码方式. 首先从几个简单的 Lambda 表达式 ...
- Chapter 7 -- Functional
Caveats 说明 As of Java 7, functional programming in Java can only be approximated through awkward and ...
- 深入理解Java 8 Lambda(语言篇——lambda,方法引用,目标类型和默认方法)
作者:Lucida 微博:@peng_gong 豆瓣:@figure9 原文链接:http://zh.lucida.me/blog/java-8-lambdas-insideout-language- ...
- Java资源大全中文版(Awesome最新版)
Awesome系列的Java资源整理.awesome-java 就是akullpp发起维护的Java资源列表,内容包括:构建工具.数据库.框架.模板.安全.代码分析.日志.第三方库.书籍.Java 站 ...
- Java 8新特性-1 函数式接口
Java 8 引入的一个核心概念是函数式接口(Functional Interfaces). 通过在接口里面添加一个抽象方法,这些方法可以直接从接口中运行. 如果一个接口定义个唯一一个抽象方法,那么这 ...
- JDK各个版本的新特性jdk1.5-jdk8
JDK各个版本的新特性 对于很多刚接触java语言的初学者来说,要了解一门语言,最好的方式就是要能从基础的版本进行了解,升级的过程,以及升级的新特性,这样才能循序渐进的学好一门语言.今天先为大家介绍一 ...
随机推荐
- Android开发之WebService介绍
经常有网友问:“在Android平台如何调用WebService”?经过沟通我发现,甚至有些朋友连什么是WebSerivce都不知道就在问怎么使用,更别说和WebService有关的SOAP.WSDL ...
- UVA 11865 Stream My Contest(最小树形图)
题意:N台机器,M条有向边,总资金C,现要到搭建一个以0号机(服务器)为跟的网路,已知每条网线可以把数据从u传递到v,其带宽为d,花费为c,且d越大,传输速度越快,问能够搭建的传输速度最快的网络d值是 ...
- 编译安装lnmp
http://wenku.baidu.com/view/ec45d5dd28ea81c758f578cc.html
- 嵌入式 hi3518c下ramdisk文件系统与文件系统烧写以及uboot中change-the-env
NULL RAM : mkdir ramdisk_test 临时挂在点 dd if=/dev/zero of=123 bs=1k count=10000 建立空硬盘 losetup /dev/loo ...
- Android 的实现TextView中文字链接的4种方法
Android 的实现TextView中文字链接的方式有很多种. 总结起来大概有4种: 1.当文字中出现URL.E-mail.电话号码等的时候,可以将TextView的android:autoLink ...
- webdriver(python)学习笔记六——操作测试对象
定位到具体对象后,就需要对其进行操作,比如点击.输入内容等. 一般来说,webdriver中比较常用的操作对象的方法有下面几个 click 点击对象 send_keys 在对象上模拟按键输入 clea ...
- QC开发只能修改指派给自己的缺陷,而其他的bug可以查看但是不允许修改
今天在QC9.0项目中增加了几个项目,然后我的想法是:开发只能修改指派给自己的缺陷,而其他的bug可以查看但是不允许修改 虽说qc我还是比较熟悉的,但是对于这个问题,感觉可能要用到脚本,对于脚本我一窍 ...
- JSP中字符编码转换问题
问题描述:一个input.jsp页面中的参数,传递到另外一个save.jsp页面上,然后存入到数据库中,如果input.jsp页面输入偶数中文没有问题,输入奇数则出现?,存入数据库的也是?. 问题源码 ...
- IOS-day01_OC中类的创建以及使用
OC中定义类 // 设计一个车类 @implementation Car : NSObject // 这个大括号里面写所有的属性 { @public int wheels ;//轮子个数 double ...
- RPC框架motan: 通信框架netty之Netty4Client
上文已经初步探讨了如何实现一个具体的transport,本文就来讨论一个具体的transport,本文讨论netty4的的相关实现.老规矩,看看motan-transport的目录结构. 其中最重要的 ...