Search code examples
kotlinintellij-idea

How to show toString() at IntelliJ debug of kotlin.time.Duration


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?


Solution

  • This has been reported as a bug - IDEA-335220. A similar bug is "In Progress", so this will probably be fixed in the near future.

    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.