Cody Engel
09/04/2019, 9:09 PMprivate inline fun <reified T : Any> T.`💩`(fieldName: String, fieldValue: Any) {
val attribute = this::class.java.getDeclaredField(fieldName)
attribute.isAccessible = true
attribute.set(this, fieldValue)
}
// call site
agent.`💩`("id", agentId)
karelpeeters
09/04/2019, 9:23 PMCody Engel
09/04/2019, 9:30 PMCody Engel
09/04/2019, 9:31 PMsetPrivateField
which is probably the most ideal. You don’t use set
in Kotlin, and you don’t want to set a private field
so it should hopefully raise enough red flags in code reviews to make sure we’re only using it as a last resort.karelpeeters
09/04/2019, 9:45 PMBurkhard
09/05/2019, 12:09 AMJvmSynthetic
annotation. That way it can’t be accessed from java.gildor
09/05/2019, 6:16 AMtddmonkey
09/05/2019, 7:20 AMCody Engel
09/05/2019, 6:20 PMattributes
property so reflection ended up being the quickest route