Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change kotlin val in debugger

How change val property (not method variable) in debugger?

Yes, I know that val is final analog

Breakpoint here:

Code with breakpoint

Set value disabled in context menu:

Context menu

Evaluate not work:

Evaluate window

like image 864
Nick Avatar asked Apr 12 '19 14:04

Nick


2 Answers

I was able to modify val value on the fly using "evaluate and log". Check full answer enter image description here

like image 142
Islam Salah Avatar answered Dec 26 '22 17:12

Islam Salah


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.

like image 32
Simulant Avatar answered Dec 26 '22 17:12

Simulant