delegated-properties

How to get the name of a variable in Kotlin?

怎甘沉沦 提交于 2020-01-11 09:17:43
问题 I have a Kotlin class in my application with a lot of attributes, what I want to build is a method that stores the variable name in a dictionary. The dictionary looks like this: HashMap<String, Pair<Any, Any>>() The purpose of this is to store the changes made to a certain attribute, I store the name of the variable as the key and in the Pair I store the old value and the new value. To notify a change I use the Observer pattern. So whenever a setter is called from an attribute a change will

How to get the name of a variable in Kotlin?

偶尔善良 提交于 2020-01-11 09:16:47
问题 I have a Kotlin class in my application with a lot of attributes, what I want to build is a method that stores the variable name in a dictionary. The dictionary looks like this: HashMap<String, Pair<Any, Any>>() The purpose of this is to store the changes made to a certain attribute, I store the name of the variable as the key and in the Pair I store the old value and the new value. To notify a change I use the Observer pattern. So whenever a setter is called from an attribute a change will