2장 동작 파라미터화 코드 전달하기
자바 8 인 액션 2장을 요약한 내용 입니다.
동작 파라미터화
public static List<Apple> filterGreenApples(List<Apple> inventory) {
List<Apple> result = new ArrayList<>();
for (Apple apple: inventory) {
if ("green".equals(apple.getColor()) {
result.add(apple);
}
}
return result;
}public static List<Apple> filterApples(List<Apple> inventory, String color, int weight, boolean flag) {
List<Apple> result = new ArrayList<>();
for (Apple apple: inventory) {
if ((flag && apple.getColor().equals(color)) ||
(!flag && apple.getWight() > weight)) { // 색이나 무게에 따라 필터링 한다.
result.add(apple);
}
}
return result;
}형편없는 코드다
익명 클래스
람다 표현식
추상화
실전 예제
Comparator로 정렬하기
Runnable로 코드 블록 실행하기
요약
Last updated