当前位置:网站首页>Four functional interfaces (required)
Four functional interfaces (required)
2022-06-22 06:18:00 【Kuxiaoya】
In functional interface , Look at the source code :
1、 Super many FunctionalInterface
2、 Simplify the programming model , It is widely used at the bottom of the new version of the framework !
@FunctionalInterface
public interface Runnable {
public abstract void run();
}
What are the four functional interfaces ?
Function Functional interface : There is an input parameter , There's an output
Predicate Assertive interface : There is an input parameter , The return value can only be Boolean value !
Consumer Supply type interface : Only the input , no return value
Supplier Supply type interface : No parameters , Only the return value
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-M4ZBJQwQ-1655057388443)(C:\Users\38492\AppData\Local\Temp\1655055413345.png)].](/img/e1/1abd6d082624a0880c75d2c4560d5f.png)
Code testing :
Function Functional interface
package function;
import java.util.function.Function;
/** * Function Functional interface , There is an input parameter , There's an output * As long as it is Functional interface It can be used Lambda Expression simplification */
public class Demo1 {
public static void main(String[] args) {
// Tool class : Output input value
// Function function = new Function<String,String>() {
// @Override
// public String apply(String s) {
// return s;
// }
// };
Function function = (str)-> {
return str;
};
System.out.println(function.apply("asd"));
}
}
Predicate Assertive interface
package function;
import java.util.function.Predicate;
/** * Assertive interface : There is an input parameter , The return value can only be Boolean value ! */
public class Demo2 {
public static void main(String[] args) {
// Determines if the string is empty
// Predicate<String> predicate = new Predicate<String>() {
// @Override
// public boolean test(String s) {
// return s.isEmpty();
// }
// };
Predicate<String> predicate = (str)-> {
return str.isEmpty();
};
System.out.println(predicate.test(""));
}
}
Consumer Consumer interface
package function;
import java.util.function.Consumer;
/** * Consumer Consumer interface : Only the input , no return value */
public class Demo3 {
public static void main(String[] args) {
// Consumer<String> consumer = new Consumer<String>() {
// @Override
// public void accept(String s) {
// System.out.println(s);
// }
// };
Consumer<String> consumer = (str)->{
System.out.println(str);
};
consumer.accept(" Kuxiaoya !");
}
}
Supplier Supply type interface
package function;
import java.util.function.Supplier;
/** * Supplier Supply type interface : No parameters , Only the return value */
public class Demo4 {
public static void main(String[] args) {
// Supplier<String> supplier = new Supplier<String>(){
// @Override
// public String get() {
// return " Ha ha ha ";
// }
// };
Supplier<String> supplier =()->{
return " Kuxiaoya !";
};
System.out.println(supplier.get());
}
}
边栏推荐
- 生信文献学习(part1)--PRECISE: a ... approach to transfer predictors of drug response from pre-clinical ...
- 反射操作注解
- 生信可视化(part2)--箱线图
- Single cell paper record (Part11) -- clustermap for multi-scale clustering analysis of spatial gene expression
- Huiding technology gr551x series development board supports openharmony
- Inserting a classdiagram into markdown
- 入门级测试Kotlin实现PopWindow弹窗代码
- Mail sending function is realized through SMTP protocol and exchange
- Overview of coherent sonar Geoswath
- Lock lock (key)
猜你喜欢

No business series 7: removing spots from old photos

leetcode每周3道(八)图之最短路

Pyg tutorial (7): dissecting neighborhood aggregation

单细胞文献学习(part2)--stPlus: a reference-based method for the accurate enhancement of ST

关于MNIST线性模型矩阵顺序问题

线程池的七大参数及自定义线程池

四大函数式接口(必需掌握)

PyG教程(7):剖析邻域聚合

单细胞论文记录(part14)--CoSTA: unsupervised convolutional neural network learning for ST analysis

Huiding technology gr551x series development board supports openharmony
随机推荐
Research on dynamics and control of single ball robot
Producer and consumer issues
h = key.hashCode()) ^ (h >>> 16) 详细解读以及为什么要将hashCode值右移16位并且与原来的hashCode值进行异或操作
Shengxin visualization (Part1) -- histogram
Swagger common annotation summary
MYSQL牛客刷题
常用的辅助类—(重点)
SQL injection vulnerability (XIV) XFF injection attack
东郊到家开发技术服务
性能对比分析
集合类并发不安全问题
单细胞论文记录(part7)--DL and alignment of spatially resolved single-cell transcriptomes with Tangram
什么是JUC
[technical notes]
Configuration files required for SSM integration and error reports caused by common configuration errors
CGIC文件上传----菜鸟笔记
[Examen des points clés de l'informatique en nuage]
关于MNIST线性模型矩阵顺序问题
【Rust笔记】01-基本类型
Huiding technology gr551x series development board supports openharmony