问题
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!
回答1:
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:
回答2:
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.
来源:https://stackoverflow.com/questions/58487806/how-to-change-a-value-while-debugging-to-a-variable-using-a-conditional-breakpoi