Hi, what's the most idiomatic way to define and us...
# announcements
l
Hi, what's the most idiomatic way to define and use a custom
toString()
(for debugging purposes) for a java class that doesn't override the one from
Object
?
j
Copy code
interface Debuggable {
   val debugMsg: String
fun <T : Debuggable> debug(name: String): T {
    println("DEBUG: ${name} = ${debugMsg}")
    return this
}
}
l
@jmfayard This is not my class, I can't add an interface to it. I ended up writing using a
print()
extension function that returns what a proper
toString()
should return for now.
k
You could also open a proper debugging session, and set breakpoints, so you can see actual values held by the object in question I’m assuming you’re running in an environment where this kind of thing is possible
c
Hopefully this will become possible if type classes get added to Kotlin (being discussed in a KEEP right now)
👍🏽 1