Sobes.tech
Junior — Senior

Detecting errors in a Kotlin class with a data class

livecode

Task condition

Find and explain the shortcomings of the presented Kotlin code fragment. The example uses a data class with private fields and an extension function that attempts to access them.

data class Person(private val givenName: String, private val familyName: String)

fun Person.fullName() = "${this.givenName} ${this.familyName}"

fun main() {
    println(Person("John", "Doe").fullName())
}