Skip to content

Instantly share code, notes, and snippets.

@rcgroot
Last active October 31, 2019 07:24
Show Gist options
  • Save rcgroot/dc21dd63d12d1a140e163e68c8e3bc3c to your computer and use it in GitHub Desktop.
Save rcgroot/dc21dd63d12d1a140e163e68c8e3bc3c to your computer and use it in GitHub Desktop.
internal fun <S : Any> Any.accessField(fieldName: String): S? =
javaClass.getDeclaredField(fieldName).let { field ->
field.isAccessible = true
return@let field.get(this) as S
}
internal fun Any.writeField(fieldName: String, value: Any) =
javaClass.getDeclaredField(fieldName).let { field ->
field.isAccessible = true
field.set(this, value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment