供给型 接口: 无入参,有返回值(T : 出参类型)
调用方法: T get();
用途: 如 无参的工厂方法,即工厂设计模式创建对象,简单来说就是 提供者
- /**
- * * @param
the type of results supplied by this supplier - */
- @FunctionalInterface
- public interface Supplier
{ - T get();
- }
- public class Student {
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
- }
- public static Student newStudent() {
- Supplier
supplier = () -> { - Student student = new Student();
- student.setName("默认名称");
- return student;
- };
- return supplier.get();
- }
- public static void main(String[] args) {
-
- Student student = newStudent();
- log.info(student.getName());
- }