Читать книгу Programming Kotlin Applications - Бретт Мак-Лахлин, Brett McLaughlin - Страница 85

Listing 2.9 Getting the fullName property correct (partially)

Оглавление

package org.wiley.kotlin.person class Person(_firstName: String, _lastName: String, _height: Double, _age: Int, _hasPartner: Boolean) { var firstName: String = _firstName set(value) { field = value } var lastName: String = _lastName set(value) { field = value } var height: Double = _height var age: Int = _age var hasPartner: Boolean = _hasPartner var fullName: String = combinedNames() fun combinedNames(): String { return "$firstName $lastName" } override fun toString(): String { return fullName } }

Programming Kotlin Applications

Подняться наверх