I am trying to debug my Kotlin code in IntelliJ IDEA. When I use a kotlin.time.Duration object and print it using println, I get the expected output in the console ("1h"). However, when I check the variable in the debugger, it shows a long value (7200000000000).
Here's an example:
val test: Duration = 1.hours
println(test) //Consol out = "1h"
Debugger shows:
test: long = 7200000000000
Is there a way to make the debugger display the toString() representation of the Duration object, similar to what println shows?
This has been reported as a bug - IDEA-335220.
This happens because Duration
is a value class that wraps a Long
. The debugger shows the inlined Long
, instead of using the value class's toString
implementation.
For now, you can evaluate the variable using the "Evaluate Expression" box. The result of toString
will show up there.