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

LISTING 2.3: Person with extra properties

Оглавление

package org.wiley.kotlin.person class Person(var firstName: String, var lastName: String) { var fullName: String var height: Float var age: Int var hasPartner: Boolean // Set the full name when creating an instance init { fullName = "$firstName $lastName" } override fun toString(): String { return fullName } }

You'll notice that each of these new properties has a type: String or Float or Int. Simple enough.

Now, there are some interesting things about the types of these variables, but before getting to that, there's actually a new problem in Person (in addition to that last name thing that still needs to be dealt with).

Programming Kotlin Applications

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