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

Custom-Set Properties Can't Be in a Primary Constructor

Оглавление

What a mouthful! It's true, though: because we want to take control of what happens when a first or last name is changed, we're going to have to make a lot of changes to how Person is constructed. Basically, we have to override the accessor for firstName and lastName. To do that, we cannot have those properties initialized in the Person primary constructor.

NOTE You may have noticed the term “primary constructor” here. Think of that simply as “the constructor” for now. Later, you'll see that Kotlin lets you define multiple constructors, and the primary one is the one defined on the first line of the class—the one you already have.

More on this later, though, so don't worry too much about primary and secondary constructors for now.

Programming Kotlin Applications

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