public static String fieldAndAccessor(PersonWithPublicFields person) {
return
person.givenName + “ “ +
person.getFullName();
}
코틀린에서는 이런 일이 생기지 않는다. 멋지게도 심지어 자바 필드와 계산된 프로퍼티 메서드
에 접근할 때도 접근 방식이 동일하다.
fun fieldAndAccessor(person: PersonWithPublicFields) =
person.givenName + “ “ +
person.fullName
코틀린에서는 생성자 밖에서 계산된 프로퍼티를 정의한다.
data class PersonWithProperties(
val givenName: String,
val familyName: String,
val dateOfBirth: LocalDate
) {
val fullName get() = “$givenName $familyName”
}
따라서 자바에서는 필드에 직접 접근하는 클래스를 정의할 수
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.