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

자바에서 코틀린으로

by 덩컨 맥그레거, 냇 프라이스, 오현석
November 2022
Beginner to intermediate
544 pages
12h 39m
Korean
Hanbit Media, Inc.
Content preview from 자바에서 코틀린으로
51
3
자바 클래스에서 코틀린 클래스로
}
}
코틀린이 자바보다 덜 간결해 보이는 곳으로, 정적 상태와 메서드를 포함시키기 위해 사용하는
동반 객체를 들 수 있다. 본 예제의
parse
()
가 이에 해당한다. 코틀린에서는 최상위 상태와 함
수를 이런 클래스 영역의 멤버로 두는 것을 선호하는 경우가 흔히 있다.
8
장에서 이런 방식의
장단점에 대해 다룬다.
현재 우리에게는 정적 메서드를 사용하는 자바 코드가 있다. 예를 들어, 테스트에는 다음과 같
은 코드가 있다.
예제
3.5
[classes.0:src/test/java/travelator/EmailAddressTests.java]
public class EmailAddressTests {
@Test
public void parsing() {
assertEquals(
new EmailAddress(“fred”, “example.com”),
EmailAddress.parse(“fred@example.com”)
);
}
@Test
public void parsingFailures() {
assertThrows(
IllegalArgumentException.class,
() -> EmailAddress.parse(“@”)
);
...
}
...
}
동반 객체와
@
JvmStatic ...
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