Skip to content

Instantly share code, notes, and snippets.

@nhoxbypass
Created February 15, 2020 10:03
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 nhoxbypass/4d07f8c9304571198133a292cd084fae to your computer and use it in GitHub Desktop.
Save nhoxbypass/4d07f8c9304571198133a292cd084fae to your computer and use it in GitHub Desktop.
@Throws(Exception::class)
fun setFinalStatic(field: Field, newValue: Any) {
field.setAccessible(true)
val modifiersField = Field::class.java.getDeclaredField("modifiers")
modifiersField.setAccessible(true)
modifiersField.setInt(field, field.getModifiers() and Modifier.FINAL.inv())
field.set(null, newValue)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment