2

In an Java Project this is possible while debugging by “mis”-using a conditional breakpoint to set a value to a property or variable:

Java Breakpoint

Unfortunately the same thing is not possible in a Kotlin Project. The error is: Assignments are not expressions, and only expressions are allowed in this context:

Kotlin Breakpoint

I know that I can do it in debugger window using “Set Value”, but then i have to do it every time manually. Using a conditional breakpoint/watchpoint the value is set automatically without even suspending the program until I delete the breakpoint. This is pretty useful for smoke test or presentations.

Thanks in advance!

ilkos
  • 29
  • 4

2 Answers2

2

Do not do that in the condition field, use "evaluate and log" - this breakpoint action is created specifically for this.

Also you can unset "suspend" and it will silently set value for you:

enter image description here

Egor
  • 2,474
  • 17
  • 19
1

You could execute a function to set the value:

run { text = "Some Value" }

This is an expression; it returns Unit, but has the side effect of setting your variable.

If the condition field needs you to return a boolean you can add it after:

run { text = "Some Value"; false }

This returns false so the execution wouldn't stop.

RobCo
  • 6,240
  • 2
  • 19
  • 26