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

LISTING 1.3: A less useless object in Kotlin and its constructor

Оглавление

class Person constructor(firstName: String, lastName: String) { /* This class still doesn't do much! */ } fun main() { val brian = Person("Brian", "Truesby") }

Now the class takes in a few useful properties. But, as most developers know, there's a tendency to condense things in code. There's a general favoring of typing less, rather than typing more. (Note that this rarely applies to book authors!) So Listing 1.3 can be condensed; you can just drop the word constructor and things work the same way. Listing 1.4 shows this minor condensation (and arguable improvement).

Programming Kotlin Applications

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