lundi 30 mai 2022

Why class member property reflection in Kotlin?

In 'Kotlin in Action', it says "if a memberProperty refers to the age property of the Person class, memberProperty.get(person) is a way to dynamically get the value of person.age" with code(10.2.1 The Kotlin Reflection API):

class Peron(val name: String, val age: Int)
>> val person = Person("Alice", 29)
>> val memberProperty = Person::age
>> println(memberProperty.get(person))
29

I can't understand why this example refers to "dynamically" getting the value of property. It just works when I run this code:

println(person.age)

Is there any other case or example of member property reflection?





Aucun commentaire:

Enregistrer un commentaire