Colton Idle
03/09/2024, 7:01 AMval field = CryptoFormat::class.java.getDeclaredField("NON_RAW_PREFIX_SIZE")
field.isAccessible = true
val modifers = field.javaClass.getDeclaredField("modifiers")
modifers.isAccessible = true
modifers.setInt(field, field.modifiers and java.lang.reflect.Modifier.FINAL.inv())
field.setInt(null, 2000)
val newValue = CryptoFormat.NON_RAW_PREFIX_SIZE
println("NON_RAW_PREFIX_SIZE is now: $newValue")
Error: java.lang.NoSuchFieldException: modifiers
ephemient
03/09/2024, 7:38 AMephemient
03/09/2024, 7:38 AMephemient
03/09/2024, 7:40 AMephemient
03/09/2024, 7:43 AMstatic final
values that follow certain rules (Kotlin makes it explicit with const
), and this is one of them. so changing the value at runtime does nothing to existing codeColton Idle
03/09/2024, 7:49 AMKlitos Kyriacou
04/23/2024, 10:46 AMNON_RAW_PREFIX_SIZE
was an instance of a class that had a field called modifiers
. I think you meant to call getModifiers()
instead.ephemient
04/24/2024, 10:07 AMfinal
modifier in reflection by modifying (via reflection) the reflected Field
. now you are not allowed to access java.base
reflectively, so that trick no longer works