Java8 Supplier
来源:互联网 发布:购买高权重网站域名 编辑:程序博客网 时间:2024/06/06 12:43
package com.lgx.jdk8.part01;import java.util.function.Supplier;/** * 函数式接口Supplier */public class Test12Supplier { public static void main(String[] args) { Supplier<String> supplier = () -> "hello world"; //get方法不接受参数,返回一个结果 System.out.println("supplier = [" + supplier.get() + "]"); //替代不接受参数的工厂方法 Supplier<Student> studentSupplier = () -> new Student(); System.out.println(studentSupplier.get()); //因为Student的构造方法不接受参数,返回一个结果,符合Supplier接口的要求,可以简写如下: Supplier<Student> studentSupplier2 = Student::new; System.out.println(studentSupplier2.get()); }}class Student{ private String name = "zhangsan"; private int age = 25; //删掉这个会报错 public Student() { } //加上这个也不报错 public Student(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "Student{" + "name='" + name + '\'' + ", age=" + age + '}'; }}
阅读全文
0 0
- Java8 Supplier
- java8:Supplier和Stream
- JAVA8-Supplier函数
- java8-supplier源码
- JAVA8 Function、Consumer、Predicate、Supplier接口
- 【java】【java8】Lambda、Stream、Function、Consumer、Predicate、Supplier
- Java8 java.util.function包解析(Function,Consumer,Predicate,Supplier)
- Supplier Data Model Stuff
- Implementing an authentication supplier
- supplier\site\bank --infomation
- Guava学习笔记-Supplier
- Supplier Tax Payer ID
- Supplier Address Book
- R12 Supplier Emails
- R12 Supplier simple data
- R12 Disabled Supplier
- guava Function Predicate Supplier
- guava Function Predicate Supplier
- React中Mixin的使用
- GameEntity(六)—— IChat
- python np库小知识点补充 mat npy 转换
- 单例与多线程
- android基础UI控件
- Java8 Supplier
- PHP——你应该知道的面试题
- svn上传拉取
- 数据结构-循环队列的基本操作
- iOS11 & iPhone X 适配指南
- 自定义圆形进度条
- PC标签保留参数phpcms
- 左填充-LintCode
- (工作中)springmvc的对字典表的使用@dict