How change val
property (not method variable) in debugger?
Yes, I know that val
is final analog
Breakpoint here:
Set value
disabled in context menu:
Evaluate not work:
How change val
property (not method variable) in debugger?
Yes, I know that val
is final analog
Breakpoint here:
Set value
disabled in context menu:
Evaluate not work:
In the debugger select the value use the context menue on right click to select "set Value..." (default shortcut F2). The value of the variable should now be displayed in a text field. Enter the desired value and press enter to change the value. You only need to enter the value not an assignment (e.g. x = "test"
is wrong, just enter the value "test"
). The changed value is now applied to the field.
In the debugger it IS also possible to change values on immutable val
defined values in Kotlin as it is also possible to change the value on final
defined variables in Java.
You can do it using reflection.
Just open the Evaluate Expression menu, then type:
val field = Main::class.java.getDeclaredField("b")
field.isAccessible = true
field.set(b, true)
I was able to modify val
value on the fly using "evaluate and log".
Check full answer