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

You Can Explicitly Tell Kotlin What Type to Use

Оглавление

You have two ways to fix this. The easiest is to tell Kotlin that you want the value you're passing in to be treated as a Float ; you can do that by putting a capital F after the number:

val brian = Person("Brian", "Truesby", 68.2F, 33, true) println(brian) // Create another person val rose = Person("Rose", "Bushnell", 56.8F, 32, true) println(rose)

In this case, you're sending Person what it wants: a Float. That passes the type checking and things are OK again.

Programming Kotlin Applications

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