Created
November 5, 2019 17:06
-
-
Save BetweenTwoBits/41d48da7f9532667d852c67b9f6c9682 to your computer and use it in GitHub Desktop.
Get Enum values using reflection hacks
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
// 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