Last active
October 31, 2019 07:24
-
-
Save rcgroot/dc21dd63d12d1a140e163e68c8e3bc3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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