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语言的初学者来说,要了解一门语言,最好的方式就是要能从基础的版本进行了解,升级的过程,以及升级的新特性,这样才能循序渐进的学好一门语言.今天先为大家介绍一 ...
随机推荐
- mysql设置指定ip远程访问连接实例
1. 授权用户root使用密码jb51从任意主机连接到mysql服务器: 复制代码代码如下: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED ...
- css虚线和css双实线
border线型主要有:1.dotted[点状]2.solid[实线] 3.double[双实线] 4.dashed;[虚线] 如果一个CSS这样写:border-style:dotted solid ...
- busybox filesystem ts_config: No such file or directory
/******************************************************************** * busybox filesystem ts_config ...
- 物联网操作系统HelloX应用编程指南
HelloX操作系统应用编程指南 HelloX应用开发概述 可以通过三种方式,在HelloX操作系统基础上开发应用: 1. 以内部命令方式实现应用,直接编译链接到HelloX的内核she ...
- django - 好的 获取 参数值 方法
第一步: # 参数列表 parameters = ('user_id', 'day_time', 'normal_data', 'hourly_data', 'product_id') # 需要传入的 ...
- 【转】iOS-延迟操作方法总结
原文网址:http://lysongzi.com/2016/01/30/iOS-%E5%BB%B6%E8%BF%9F%E6%93%8D%E4%BD%9C%E6%96%B9%E6%B3%95%E6%80 ...
- 总结mysql服务器查询慢原因与解决方法
本文针对MySQL数据库服务器查询逐渐变慢的问题, 进行分析,并提出相应的解决办法,具体的分析解决办法如下: 会经常发现开发人员查一下没用索引的语句或者没有limit n的语句,这些没语句会对数据库造 ...
- Python easy_install
系统中有高版本的Python, 直接pip3 install ipcalc安装,都是装到高版本的Python 系统默认的Python是2.7.6,现在想装到默认版本中,可以使用easy_install ...
- Hadoop中OutputFormat解析
一.OutputFormat OutputFormat描述的是MapReduce的输出格式,它主要的任务是: 1.验证job输出格式的有效性,如:检查输出的目录是否存在. 2.通过实现RecordWr ...
- java jvm学习笔记十一(访问控制器)
欢迎装载请说明出处: http://blog.csdn.net/yfqnihao/article/details/8271665 这一节,我们要学习的是访问控制器,在阅读本节之前,如果没有前面几节的 ...