Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kotlin companion object field with debugger

I declare a field in companion object, so it will be known in the functions in the companion object.

something like this:

class ProgramStructure {
  companion object {
      var index = 0
      fun inc(){
          index++
      }
  }
}

Everything work perfect, but when I debugging it I can't see the value of "index". How can I see the value?

Thanks

like image 223
nirKa Avatar asked May 21 '18 20:05

nirKa


1 Answers

I assume you are using IntelliJ IDEA.

Since index is neither a local variable nor a field of the current instance, there's no straightforward way to see its value in the debugger.

If you need to evaluate index once, you can use the Evaluate Expression action (the default keyboard shortcut is Alt+F8), which is available in the debug window:

enter image description here

Then type index:

enter image description here

Another way to evaluate an expression is to Alt+click it in the editor, or select it and press Ctrl/Cmd+Alt+F8.


If you want to watch the index values over time, consider adding a watch (New Watch, Insert in the debug window, or from the Evaluate Expression dialog), and here's how it looks with the watch:

enter image description here

like image 78
hotkey Avatar answered Oct 19 '22 11:10

hotkey