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

자바에서 코틀린으로

by 덩컨 맥그레거, 냇 프라이스, 오현석
November 2022
Beginner to intermediate
544 pages
12h 39m
Korean
Hanbit Media, Inc.
Content preview from 자바에서 코틀린으로
364
자바에서 코틀린으로
TIP
코틀린에서 가짜 객체 도입하기
단순히 테스트를 위해 인터페이스의 메서드 중 일부를 구현하고 싶어했던 시절이 있었다. 심지어 코틀린에서
도 그랬다.
JVM
에서 동적 프락시와 익명 객체, 위임, 선택적인 오버라이딩을 조합해서 다음과 같이 코드를 작
성했다.
inline fun <reified T> fake(): T =
Proxy.newProxyInstance(
T::class.java.classLoader,
arrayOf(T::class.java)
) { _, _, _ ->
TODO(“not implemented”)
} as T
val sentEmails = mutableListOf<Email>()
val testCollaborator: EmailSystem =
object : EmailSystem by fake() {
override fun send(email: Email) {
sentEmails.add(email)
}
}
17.2
그렇지만 실제 목에서 벗어났는가?
이 질문은 좋은 질문이다!
어떤 면에서 이제 막 목 프레임워크를 조악하게 본딴 물건을 만들었다. 파라미터 매처도 없고
메서드를 호출할 수 없을 때, 테스트를 실패시킬 방법도 없으며 실행 순서를 표현할 수 있는 방
법도 없다.
하지만 다른 방법을 ...
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