https://kotlinlang.org logo
Title
m

Mike R

07/05/2019, 5:30 PM
Is there a way to get all the properties on an object (for example to print them out)? In Python, I would do
my_obj.__dir__
a

Adam Powell

07/05/2019, 5:37 PM
For what kind of use case? For exploration you have IDE autocompletion vs. python's exploration in the repl. For debugging/logging you have
.toString()
which is autogenerated for data classes to print each property where you most often need this sort of thing. And then there's the debugger itself.
You can iterate over the properties of an object using reflection, but it's frowned upon because there's probably a better way to accomplish whatever you're trying to do with it.
m

Mike R

07/05/2019, 5:52 PM
to
toString()
should work perfect since they are data classes, thank you!