What I Learned

크롱의 수업

함수형 프로그래밍

FP v. OOP

자바의 정석 / 유투브

유투브 비디오 Java Functional Programming by Amigoscode 를 참고했다.

Method Reference

메소드 참조는 람다식을 간략하게 작성하는 방식이다.

Integer method(String s) { // 메소드를 길게 푼 형식
	return Integer.parseInt(s);
}

int result = Integer.parseInt(s); // 위의 method를 간략하게 표현해서 result 변수에 넣음

Function<String, Integer> method = s -> Integer.parseInt(s); // 람다식

람다식에서 (x) -> ClassName.method(x) 로 표현되는 것을 메소드 참조로는 ClassName::method로 표현된다. 인풋이나 아웃풋의 변수타입은 Function 인터페이스의 지네릭 타입으로부터 알 수 있어서 생략한다.

Function<String, Integer> method = Integer::parseInt; // 메소드 참조