https://kotlinlang.org logo
Title
c

Czar

03/14/2018, 5:33 PM
you could do this, but this is ugly as hell: 😈 :java:
data class Person(val name: String, val age: Int) {
	init {
		Person::class.memberProperties
			.find { it.name == "name" }
			?.javaField
			?.let {
				it.isAccessible = true
				it[this] = "${it[this] as String}suffix"
				it.isAccessible = false
			}
	}
}
😆 1
😱 2
By the way is the
it.isAccessible = false
really necessary? I almost never use reflection, so my knowledge of the matter is a bit lacking.
test shows that yes, it is necessary