Skip to Content
Java에서 Kotlin으로
book

Java에서 Kotlin으로

by Duncan McGregor, Nat Pryce
May 2025
Beginner to intermediate
424 pages
7h 7m
Korean
O'Reilly Media, Inc.
Book available
Content preview from Java에서 Kotlin으로

3장. Java에서 Kotlin으로 클래스 전환하기

이 작품은 AI를 사용하여 번역되었습니다. 여러분의 피드백과 의견을 환영합니다: translation-feedback@oreilly.com

클래스는 Java에서 코드 구성의 기본 단위입니다. Java 클래스를 Kotlin으로 변환하려면 어떻게 해야 하며, 변환하면 어떤 차이가 있을까요?

이 책에서는 가상의 여행 계획 웹 앱인 Travelator의 코드를 함께 작업해 보겠습니다. 구현할 기능이 있지만 구현하기 전에 코드를 조금 더 개선할 기회를 갖고 싶다고 상상해 보겠습니다. Nat 또는 Duncan 중 한 명과 짝을 이룹니다(마음에 드는 사람을 선택하고, Nat에게는 알리지 마세요). 짝은 리팩터링 토론에서 작성자뿐만 아니라 Travelator를 개발하는 팀의 일원으로서 여러분도 포함됩니다. 환영합니다!

단순 값 유형

코드베이스의 심층으로 들어가서 기존 Java의 일부를 EmailAddress 로 시작하는 Kotlin으로 변환해 보겠습니다. 이것은 이메일 주소의 두 부분을 담고 있는 값 유형입니다:

public class EmailAddress {
    private final String localPart; 1
    private final String domain;

    public static EmailAddress parse(String value) { 2
        var atIndex = value.lastIndexOf('@');
        if (atIndex < 1 || atIndex == value.length() - 1)
            throw new IllegalArgumentException(
                "EmailAddress must be two parts separated by @"
            );
        return new EmailAddress(
            value.substring(0, atIndex),
            value.substring(atIndex + 1)
        );
    }

    public EmailAddress(String
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

코드 밖 커뮤니케이션

코드 밖 커뮤니케이션

재퀴 리드
실리콘밸리 리더십

실리콘밸리 리더십

김정혜, 마이클 롭

Publisher Resources

ISBN: 9798341656055Supplemental Content