[CHAPTER 1] - 자바 8, 9, 10, 11 : 무슨 일이 일어나고 있는가? #3
Replies: 3 comments
예제 다운로드https://www.hanbit.co.kr/support/supplement_survey.html?pcode=B4926602499 |
0 replies
1.3.2 코드 넘겨주기 : 예제
public class FilteringApples {
public static void main(String... args) {
// [Apple{color='green', weight=80}, Apple{color='green', weight=155}]
List<Apple> greenApples = filterApples(inventory, FilteringApples::isGreenApple);
System.out.println(greenApples);
// [Apple{color='green', weight=155}]
List<Apple> heavyApples = filterApples(inventory, FilteringApples::isHeavyApple);
System.out.println(heavyApples);
}
public static boolean isGreenApple(Apple apple) {
return "green".equals(apple.getColor());
}
public static boolean isHeavyApple(Apple apple) {
return apple.getWeight() > 150;
}
// 1.3.3 메서드 전달에서 람다로
// [Apple{color='green', weight=80}, Apple{color='green', weight=155}]
List<Apple> greenApples2 = filterApples(inventory, (Apple a) -> "green".equals(a.getColor()));
System.out.println(greenApples2);
// [Apple{color='green', weight=155}]
List<Apple> heavyApples2 = filterApples(inventory, (Apple a) -> a.getWeight() > 150);
System.out.println(heavyApples2);
public static List<Apple> filterApples(List<Apple> inventory, Predicate<Apple> p) {
List<Apple> result = new ArrayList<>();
for (Apple apple : inventory) {
if (p.test(apple)) {
result.add(apple);
}
}
return result;
} |
0 replies
느낀점
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
1.1 역사의 흐름은 무엇인가?
리액티브 프로그래밍병렬 실행 기법 지원흐 름
메서드 참조와 람다,인터페이스의 디폴트 메서드가 존재할 수 있었다.메서드 참조와 람다) →동작 파라미터화구현 가능1.2 왜 아직도 자바는 변화하는가?
1.3 자바 함수
스트림과 연계될 수 있도록 함수를 만들었기 때문프로그래밍 언어의 핵심 :
값을 바꾸는 것메서드,클래스) 가 값의 구조를 표현하는데 도움이 될 수 있다.이급시민)All reactions