Skip to Content
자바에서 코틀린으로
book

자바에서 코틀린으로

by 덩컨 맥그레거, 냇 프라이스, 오현석
November 2022
Beginner to intermediate
544 pages
12h 39m
Korean
Hanbit Media, Inc.
Content preview from 자바에서 코틀린으로
334
자바에서 코틀린으로
val instance = EmailSender(
inetAddress(“smtp.travelator.com”),
“username”,
“password”
)
val sender: (Email) -> Unit = { instance.send(it) }
람다 대신 그냥 메서드 참조를 써도 된다.
val sender: (Email) -> Unit = instance::send
이런 변환을 코틀린에서 보여줬지만, 자바에서도 (약간 다른 문법을 사용해) 이 방법을 쓸 수
있다.
ISendEmail
인터페이스의
send
메서드의 경우에도 메서드 참조를 사용할 수 있다. 다
만 함수 타입을 사용하는 경우 인터페이스가 별로 하는 일이 없다는 사실이 그리 명확히 드러
나지는 않는다.
이와 반대로 함수형
sender
ISendEmail
을 받는 위치에 넘길 수 있을까? 이렇게 하려면 람
다를 감싸기 위한 익명 객체를 만들어야 하기 때문에, 약간의 의식이 더 필요하다.
val function: (Email) -> Unit = createEmailSender(
inetAddress(“smtp.travelator.com”),
“username”,
“password”
)
val sender: ISendEmail = object : ISendEmail ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

고성능 파이썬(2판)

고성능 파이썬(2판)

오현석, 미샤 고렐릭, 이안 오스발트
러닝 타입스크립트

러닝 타입스크립트

조시 골드버그
실리콘밸리 리더십

실리콘밸리 리더십

김정혜, 마이클 롭

Publisher Resources

ISBN: 9791169210447