기본 함수형 인터페이스
Consumer<T>
목적 : 값을 받아서 처리만 하고 반환값 없음
메서드 : void accept(T t)
예시 :
Consumer<String> printer = s -> System.out.println(s);
printer.accept("Hello");
Supplier<T>
목적 : 값을 제공만 하고 , 입력값 없음
메서드 : T(get)
Supplier<String> supplier = () -> "Hello";
String result = supplier.get(); // "Hello"
Function<T, R>
목적 : T 타입을 받아 R 타입으로 변환
메서드 : R apply(T t)
예시 :
Fuction<Integer, String> intToStr = i -> "Number: " + i;
String s = intToStr.apply(5); // "Number: 5"
Predicate<T>
목적 : T 타입 값을 받아 boolean 결과 반환 (조건 판단)
메서드 : boolean test(T t)
Predicate<String> isEmpty = s -> s.isEmpty();
boolean result = isEmpty.test(" ");
Last updated