⭐️ Supplier Interface
- 인자를 받지 않고
T를 반환(제공)한다.
Consumer 와 정확히 반대의 역할을 한다.
Consumer는 하나의 인자를 받아 소비한다.
@FunctionalInterface
public interface Supplier<T> {
T get();
}
🌱 Supplier 예시
package com.learnJava.functionalInterfaces;
import com.learnJava.data.Student;
import com.learnJava.data.StudentDataBase;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
public class SupplierExample {
public static void main(String[] args) {
Supplier<Student> studentSupplier = () -> new Student("Adam",2,3.6, "male",10, Arrays.asList("swimming", "basketball","volleyball"));
Supplier<List<Student>> listSupplier = () -> StudentDataBase.getAllStudents();
System.out.println("Student is : " + studentSupplier.get());
System.out.println("Students are : " + listSupplier.get());
}
}