I know in java if I wish to use reflection to set a final field I can change the access modifier of the field like so:
Field field = clazz.getDeclaredField("someField");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
I am have difficulty achieving the same thing in kotlin. The problem is with the bitwise operators on the final line modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL)
. Admittedly I am somewhat ignorant of bitwise operators in general and do not know the kotlin equivalent.
Aucun commentaire:
Enregistrer un commentaire