#1 Funtional Interface?
1-1 함수형 인터페이스란?
- 1개의 추상 메서드를 갖는 인터페이스
- default method 또는 static method는 여러 개를 가져도 상관 없다.
- @FuntionalInterface
- 함수형 인터페이스의 조건을 검사해준다
- 추상 메서드가 1개를 초과하는 등 조건을 어겼을 때 오류를 반환
1-2 함수형 인터페이스 만들기
@FunctionalInterface
public interface FuncInterface {
void abstMethod();
}
#2 Why?
2-1 Lambda
#3 기본 함수형 인터페이스
3-1 Predicate
- 값을 받아서 boolean 타입을 반환
- filter와 주로 쓰임
- filter의 조건을 통해 값의 true/false 여부를 판단
public class Func {
public static void main(String[] args) {
List<String> cities = Arrays.asList("Seoul", "Tokyo", "New York", "Frankfurt", "Shanghai");
List<String> cityWithS = cities.stream()
.filter(city -> city.startsWith("S"))
.collect(Collectors.toList());
System.out.println(cityWithS);
}
}
}
}
3-2 Consumer
3-3 Supplier
3-4 Function<T,R>
3-5 Comparator
3-6 Runnable
3-7 Callabel