Skip to content

Instantly share code, notes, and snippets.

@BetweenTwoBits
Created November 5, 2019 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetweenTwoBits/41d48da7f9532667d852c67b9f6c9682 to your computer and use it in GitHub Desktop.
Save BetweenTwoBits/41d48da7f9532667d852c67b9f6c9682 to your computer and use it in GitHub Desktop.
Get Enum values using reflection hacks
// This code is for obtaining values from Enums that exist in an SDK and are obfuscated for some reason.
for (errorCode in ErrorCode.values()) {
Log.info("ErrorCodes: ${errorCode.name} ${errorCode.getCode()}")
}
private fun Component.getCode():String {
return javaClass.getDeclaredField("value").let {
it.isAccessible = true
return@let it.get(this) as String
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment